Skip to content

Instantly share code, notes, and snippets.

@makoru-hikage
Last active May 31, 2023 17:37
Show Gist options
  • Save makoru-hikage/8c13b264acd7fa157b40ec41910d5f7a to your computer and use it in GitHub Desktop.
Save makoru-hikage/8c13b264acd7fa157b40ec41910d5f7a to your computer and use it in GitHub Desktop.
To avoid stack overflow, I implemented a Fibonacci using a for loop.
#!/usr/bin/python
def fibonacci (t):
if t <= 1:
return t
return (fibonacci(t - 1) + fibonacci(t - 2))
def fibonacci_set(t):
if t == 0:
return [0]
if t == 1:
return [0,1]
start = [0, 1]
index = 0
for x in range(t - 1):
start.append((start[x] + start[x+1]))
return start
f = fibonacci_set(1000)
print (f)
print ("{:e}".format(f[-1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment