Created
May 6, 2014 05:52
-
-
Save damianesteban/c60565f732f2bd140944 to your computer and use it in GitHub Desktop.
fibonacci sequence with yield
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
# Fibonacci sequence with yield / parallel assignment | |
def fib_up_to(max) | |
i1, i2, = 1, 1 # parallel assignment | |
while i1 <= max | |
yield i1 | |
i1, i2 = i2, i1 + i2 | |
end | |
end | |
fib_up_to(1000) { |f| print f, " " } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment