Created
July 1, 2012 22:32
-
-
Save pjc/3029863 to your computer and use it in GitHub Desktop.
Euler Project in Ruby - Problem 2
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
# Create Fibonnaci Array | |
a = [1,2] | |
upto = 4_000_000 | |
while a[-2] + a[-1] < upto | |
a << a[-2] + a[-1] | |
end | |
# Create sum of even Fibonnaci numbers | |
sum = 0 | |
a.each { |x| sum+= x if x.even? } | |
puts "The result is #{sum}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my solution. Personally find it easier to understand than the one given