Skip to content

Instantly share code, notes, and snippets.

@nouse
Created January 11, 2011 10:31
Show Gist options
  • Save nouse/774279 to your computer and use it in GitHub Desktop.
Save nouse/774279 to your computer and use it in GitHub Desktop.
ruby 1.9 Fibonacci with enumerator
generic_fib = -> a, b, &c { Enumerator.new{ |y| loop { y << a; a, b = b, c[a,b] }}}
fib = generic_fib[1,1, &:+]
negative_fib = generic_fib[1,-1, &:-]
p fib.take(10)
p negative_fib.take(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment