Skip to content

Instantly share code, notes, and snippets.

Created May 22, 2014 00:17
Show Gist options
  • Save anonymous/cfe05ebda55b44c51777 to your computer and use it in GitHub Desktop.
Save anonymous/cfe05ebda55b44c51777 to your computer and use it in GitHub Desktop.
# 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}"
##
summa, a, b = 0, 1, 2
while b < 4000000
summa += b if b.even?
a, b = b, a + b
end
puts summa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment