티스토리 뷰
https://projecteuler.net/problem=2
def f(n):
return n if n[-1] + n[-2] >= 4000000 else f(n + [n[-1] + n[-2]])
print(sum([i for i in f([1, 2]) if i % 2 == 0]))
# Python 3
fibonacci = [1, 2]
a = 1
b = 2
c = 3
while c < 4000000:
fibonacci.append(c)
a = b
b = c
c = a + b
total = 0
for i in fibonacci:
if i % 2 == 0:
total += i
print(total)
# Python 3
fibonacci = [1, 2]
total = 2
c = 3
while c < 4000000:
fibonacci.append(c)
total += c if c % 2 == 0 else 0
c = fibonacci[-1] + fibonacci[-2]
print(total)
# Python 3
a = 1
b = 2
c = 3
total = 2
while c < 4000000:
total += c if c % 2 == 0 else 0
a = b
b = c
c = a + b
print(total)
# Python 3
from typing import List
def fibonacci(my_list: List[int]) -> List[int]:
term: int = my_list[-1] + my_list[-2]
if term < 4000000:
my_list.append(term)
return fibonacci(my_list)
else:
return my_list
fi_list = [1, 2]
print(sum([i for i in fibonacci(fi_list) if i % 2 == 0]))
'Puzzle > ProjectEuler' 카테고리의 다른 글
[Project Euler] Problem 3: Largest prime factor (incomplete) (0) | 2019.04.19 |
---|---|
[Project Euler] Problem 1: Multiples of 3 and 5 (0) | 2019.04.19 |