Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Last active December 11, 2015 20:28
Show Gist options
  • Save georgeOsdDev/4655626 to your computer and use it in GitHub Desktop.
Save georgeOsdDev/4655626 to your computer and use it in GitHub Desktop.
メモ化でフィボナッチ数列
cache = []
fib = (i) ->
_fib = (i) ->
if i is 0 or i is 1 then return i
if cache[i]?
return cache[i]
else
cache[i] = _fib(i-1) + _fib(i-2)
_fib(i)
for i in [0..20]
console.log fib(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment