Skip to content

Instantly share code, notes, and snippets.

@0x49D1
Created January 25, 2019 06:36
Show Gist options
  • Save 0x49D1/02b8d2fba3e53d7e5d965d993c77db10 to your computer and use it in GitHub Desktop.
Save 0x49D1/02b8d2fba3e53d7e5d965d993c77db10 to your computer and use it in GitHub Desktop.
Python sample of project Euler problem 2 solution
import time
def even_sum_fib(sum_limit):
current = previous = 1
sum = 0
while(sum < sum_limit):
if current % 2 == 0:
sum += current
previous, current = current, current + previous
return sum
if __name__ == "__main__":
start = time.time()
limit = 4000000
print(even_sum_fib(limit))
end = time.time()
print(f"Elapsed seconds for sum limit of {limit}: {end - start}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment