Last active
August 29, 2015 14:17
-
-
Save kflu/dd5ee4f559ff924dab1e to your computer and use it in GitHub Desktop.
LiveScript implementation of Project Euler Problems
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
[0 to 1000] | |
|> filter (-> it % 3 == 0 or it % 5 == 0) | |
|> foldr1 (+) |
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
{unfoldr, filter, foldr1} = require 'prelude-ls' | |
fibgen = (stop, {first, second}) --> | |
| first > stop => null | |
# returns [tobe-appended, {new-first, new-second}] | |
| otherwise => [first, {first:second, second:first+second}] | |
export fib = (stop) -> unfoldr (fibgen stop), first:1 second:1 | |
console.log "fibonacci under 100: #{fib 100}" | |
result = fib 4_000_000 | |
|> filter (-> it % 2 == 0) # only even fibs | |
|> foldr1 (+) # sun | |
console.log "project euler problem 2: #result" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment