Skip to content

Instantly share code, notes, and snippets.

@fanweixiao
Created May 14, 2012 10:07
Show Gist options
  • Save fanweixiao/2693060 to your computer and use it in GitHub Desktop.
Save fanweixiao/2693060 to your computer and use it in GitHub Desktop.
Memoization fibonacci in coffeescript
fib = (n)->
arr = {}
$ = (_) ->
return _ if _ < 2
return arr[_] if arr[_]
arr[_] = $(_-1) + $(_-2)
arr[_]
$(n)
console.time('a')
console.log alert fib(500)
console.timeEnd('a')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment