Skip to content

Instantly share code, notes, and snippets.

@mythmon
Created December 4, 2010 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythmon/727956 to your computer and use it in GitHub Desktop.
Save mythmon/727956 to your computer and use it in GitHub Desktop.
# For project euler #2 -- http://projecteuler.net/index.php?section=problems&id=2
def fib(n)
@result ||= []
@result[n] ||= begin
if n <= 1
n
else
fib(n-1) + fib(n-2)
end
end
end
n = 1
sum = 0
f = 0
while f <= 4e6
f = fib(n)
sum += f if f.even?
n += 1
end
puts sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment