Last active
December 28, 2015 10:19
-
-
Save dnase/7485105 to your computer and use it in GitHub Desktop.
This file contains 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
#define a fibonacci enumerator | |
fibonacci = Enumerator.new do |yielder| | |
a = b = 1 | |
loop do | |
yielder << a | |
a, b = b, a + b | |
end | |
end | |
#curry cache to infinity | |
cache = (0..Float::INFINITY).lazy.map { |x| fibonacci(x) } | |
nth_from_list = lambda { |ary, n| ary[n] } | |
nth_fib = nth_from_list.curry[cache] | |
#list the first 100 | |
puts fibonacci.take(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment