Last active
August 29, 2015 14:04
-
-
Save tkfm-yamaguchi/fc47c16d24d5ef3cb1a4 to your computer and use it in GitHub Desktop.
fibfib(fibonacci and fiber)
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
# http://magazine.rubyist.net/?0034-FiberForBeginners | |
# | |
# fibonacci by Fiber | |
# | |
fib = Fiber.new do | |
a, b = 0, 1 | |
loop do | |
a, b = b, a + b | |
Fiber.yield(a) | |
end | |
end | |
# fibonacci main | |
10.times do | |
puts fib.resume | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment