Skip to content

Instantly share code, notes, and snippets.

@samleb
Created September 14, 2011 08:26
Show Gist options
  • Select an option

  • Save samleb/1216100 to your computer and use it in GitHub Desktop.

Select an option

Save samleb/1216100 to your computer and use it in GitHub Desktop.
fib_generator = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
fib_even_generator = Enumerator.new { |y|
fib_generator.each { |n|
y << n if n.even?
}
}
sum = 0
fib_even_generator.each do |n|
sum += n
break if n >= 4_000_000
end
puts sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment