Created
January 25, 2019 06:36
-
-
Save 0x49D1/02b8d2fba3e53d7e5d965d993c77db10 to your computer and use it in GitHub Desktop.
Python sample of project Euler problem 2 solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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