Info

Hi, I'm David Askew

I build things

Homepage

Contact Me

About

Open Source

Project Euler - Problem 002

Spoiler Alert: Don’t read this any further if you are interested in learning this on your own. The solution is below.

You have been warned.

Solution for Problem 002 from Project Euler

1
2
3
4
5
6
7
8
9
seq = [1,2]
max = 4_000_000

while seq[-2] + seq[-1] < max
  seq << seq[-2] + seq[-1]
end

evens = seq.reject{ |n| n.odd? }
puts "Answer is: #{evens.inject(:+)}"