def fibonacci(n):
SENTINEL = -1
numbers = [SENTINEL] * (n + 1)
def fibonacci(n):
if n <= 1:
return n
elif numbers[n] != SENTINEL:
return numbers[n]
else:
result = fibonacci(n - 1) + fibonacci(n - 2)
numbers[n] = result
return result
return fibonacci(n)
if __name__ == '__main__':
print(fibonacci(10))
def generate(n):
result = []
def generate_(left, right, accum):
if not left and not right:
result.append(''.join(accum))
return
if left:
accum.append('(')
generate_(left - 1, right, accum)
accum.pop()
if right > left:
accum.append(')')
generate_(left, right - 1, accum)
accum.pop()
generate_(n, n, [])
return result
if __name__ == '__main__':
print(generate(3))