Created
February 6, 2015 13:29
-
-
Save AyaMorisawa/7eaf245260ebc3cbd976 to your computer and use it in GitHub Desktop.
Project Eular 002 LiveScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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