Skip to content

Instantly share code, notes, and snippets.

@damianesteban
Created May 6, 2014 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianesteban/c60565f732f2bd140944 to your computer and use it in GitHub Desktop.
Save damianesteban/c60565f732f2bd140944 to your computer and use it in GitHub Desktop.
fibonacci sequence with yield
# 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