Skip to content

Instantly share code, notes, and snippets.

@carlwiedemann
Created October 23, 2014 18:32
Show Gist options
  • Save carlwiedemann/3e6c0a87127729f6e32b to your computer and use it in GitHub Desktop.
Save carlwiedemann/3e6c0a87127729f6e32b to your computer and use it in GitHub Desktop.
s = 0
# First two Fibbonacci terms
f_last = 1
f = 1
while f < 4 * 10**6
# Sum evens
s += f % 2 == 0 ? f : 0
# Next Fibbonacci number
f_new = f + f_last
f_last = f
f = f_new
end
puts s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment