Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SolutionTwo < Problem
- def initialize()
- @memoized = []
- end
- def fibonacci(x)
- @memoized[x] ||= x <= 1 ? x : fibonacci(x - 2) + fibonacci(x - 1)
- end
- def sequence()
- 1.upto(Float::INFINITY).lazy.map {|x| fibonacci(x)}.take_while {|x| x < 4000000}.select {|x| x.even?}
- end
- def solve()
- sequence.sum
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement