Skip to content

Instantly share code, notes, and snippets.

@thomasgassmann
Created March 24, 2022 21:10
Show Gist options
  • Select an option

  • Save thomasgassmann/3a344eba15a3a07d090325b7bc23494b to your computer and use it in GitHub Desktop.

Select an option

Save thomasgassmann/3a344eba15a3a07d090325b7bc23494b to your computer and use it in GitHub Desktop.
def fib(n):
if n <= 2:
return 1
a = [1, 1, 1]
for i in range(3, n + 1):
a[i % 3] = a[(i - 1) % 3] + a[(i - 2) % 3]
return a[n % 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment