I have just given it a try in Ruby
def fibonacci_numbers(upto) sequence = [0, 1] loop do next_number = sequence[-2] + sequence [-1] sequence.push next_number if next_number < upto break unless next_number < upto end sequence end def sum_of_even_numbers(upto) sequence = fibonacci_numbers(upto) sequence.select{ |el| el % 2 == 0 }.reduce(:+) end puts sum_of_even_numbers(4000000)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have just given it a try in Ruby