-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler2.py
More file actions
46 lines (38 loc) · 730 Bytes
/
euler2.py
File metadata and controls
46 lines (38 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Created on May 6, 2019
@author: Bharddwaj Vemulapalli
username: bvemulap
I pledge my honor that I have abided by the Stevens Honor System.
'''
v = 0
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n - 2)
print(fibonacci(1))
n = 2 #because the fib sequence in problem starts at the n = 2 term
v = 0
while True:
term = fibonacci(n)
if term < 4000000:
if term % 2 == 0:
v += fibonacci(n)
n += 1
else:
break
print(v)
#Alternative way
LIMIT = 4000000
a = 1
b = 2
sum_even = 0
while b <= LIMIT:
if b % 2 == 0:
sum_even += b
c = b
b += a
a = c
print(sum_even)