Skip to content

Instantly share code, notes, and snippets.

@kflu
Last active August 29, 2015 14:17
Show Gist options
  • Save kflu/dd5ee4f559ff924dab1e to your computer and use it in GitHub Desktop.
Save kflu/dd5ee4f559ff924dab1e to your computer and use it in GitHub Desktop.
LiveScript implementation of Project Euler Problems
[0 to 1000]
|> filter (-> it % 3 == 0 or it % 5 == 0)
|> foldr1 (+)
{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