Moved 1 to 5 to Python and learned a ton.

This commit is contained in:
2019-07-13 23:58:38 -04:00
parent 414cf4b074
commit b246d56acd
13 changed files with 402 additions and 2 deletions

24
python/e002.py Normal file
View File

@@ -0,0 +1,24 @@
from lib_fibonacci import fibonacci_generator_smaller
def euler_002():
fs = [f for f in fibonacci_generator_smaller(4000000) if f % 2 == 0]
return sum(fs)
assert(euler_002() == 4613732)
print("e002.py: {}".format(euler_002()))
def euler_002_simple():
""" Sometimes it is nice to keep it simple. Instead of using three
library functions just implement one straightforward function. """
r, a, b = 0, 0, 1
while b < 4000000:
if b % 2 == 0:
r += b
a, b = b, a + b
return r
assert(euler_002() == euler_002_simple())