Skip to content

Instantly share code, notes, and snippets.

@AyaMorisawa
Created February 6, 2015 13:29
Show Gist options
  • Save AyaMorisawa/7eaf245260ebc3cbd976 to your computer and use it in GitHub Desktop.
Save AyaMorisawa/7eaf245260ebc3cbd976 to your computer and use it in GitHub Desktop.
Project Eular 002 LiveScript
global <<< require \prelude-ls
gen-list-while = (f, max) ->
list = []
i = 0
while f(i) < max then f(i++) |> list.push
list
memoize = (memo, f) -> shell = (n) -> memo[n] ?= f shell, n
fib = memoize [1 2] (f, n) -> f(n - 1) + f(n - 2)
fib-list = gen-list-while fib, 4_000_000
fib-list |> filter even |> sum |> console.log
/*
$ lsc project-eular-002.ls
4613732
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment