Skip to content

Instantly share code, notes, and snippets.

@t-miya
Last active December 17, 2015 14:38
Show Gist options
  • Save t-miya/5625426 to your computer and use it in GitHub Desktop.
Save t-miya/5625426 to your computer and use it in GitHub Desktop.
フィボナッチ数の求め方メモ fib1の方は二重再帰で効率が悪いので末尾再帰になっているfib2の方が良い
def fib1(n):
if n<3:
return 1
else:
return fib1(n-1) + fib1(n-2)
def fib2(n, fn1=1, fn=0):
if n<1:
return fn1
else:
return fib2(n-1, fn1+fn, fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment