Created
May 26, 2011 05:43
-
-
Save johana-star/992615 to your computer and use it in GitHub Desktop.
Euler Project Problem #002
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
# Solution to Project Euler's second problem | |
# http://projecteuler.net/index.php?section=problems&id=2 | |
# Sum all even numbers in the Fibonnacci sequence below 4000000. | |
i1, i2, sum = 1, 1, 0 | |
until i1 > 4000000 | |
if i1.even? then sum = sum + i1 end | |
i1 = i1 + i2 | |
if i2.even? then sum = sum + i2 end | |
i2 = i2 + i1 | |
end | |
puts sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment