Skip to content

Instantly share code, notes, and snippets.

@yuuki
Created July 24, 2012 11:23
Show Gist options
  • Save yuuki/3169441 to your computer and use it in GitHub Desktop.
Save yuuki/3169441 to your computer and use it in GitHub Desktop.
euler2
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
fib = Enumerator.new do |y|
a, b = 0, 1
while b < 4000000 do
y << b if b % 2 == 0
a, b = b, a + b
end
end
puts fib.inject{ |sum, n| sum + n }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment