euler/crystal/euler002.cr

19 lines
240 B
Crystal
Raw Normal View History

2018-02-21 21:00:08 +00:00
def fibonacci_nums_up_to(n)
result = [1] of Int32
a = 1
b = 2
accum = 0
while accum < n
accum = a + b
result << b
a = b
b = accum
end
result
end
puts fibonacci_nums_up_to(4000000).select{ |n| n.even? }.sum