Created
June 4, 2010 01:25
-
-
Save dbyrne/424780 to your computer and use it in GitHub Desktop.
Project Euler #2 - Ruby
This file contains hidden or 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
| fibs = Fiber.new do | |
| x1, x2 = 1, 2 | |
| loop do | |
| Fiber.yield x1 | |
| x1, x2 = x2, x2+x1 | |
| end | |
| end | |
| sum = 0 | |
| begin | |
| sum += y if (y = fibs.resume).even? | |
| end while y <= 4000000 | |
| puts sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment