-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem002.py
More file actions
29 lines (19 loc) · 847 Bytes
/
Copy pathProblem002.py
File metadata and controls
29 lines (19 loc) · 847 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
#Problem 2 for Project Euler
#Sum the even fibionocci numbers below 4M.
def EvenFibSum(n):
'''returns the sum of even fibionocci numbers below n)'''
f1,f2,EFS = 1,1,0
while (EFS < n):
EFS += (f1 + f2)
f1, f2 = f1 + 2 * f2, 2 * f1 + 3 * f2
return EFS
print(EvenFibSum(10000))
#This is interesting and was pulled from Project Euler on 9/4/2015 Authored by Begoner.
#Here is their explanation:
#This may be a small improvement. The Fibonacci series is:
#1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610...
#Now, replacing an odd number with O and an even with E, we get:
#O, O, E, O, O, E, O, O, E, O, O, E, O, O, E...
#And so each third number is even. We don't need to calculate the odd numbers. Starting from an two odd terms x, y, the series is:
#x, y, x + y, x + 2y, 2x + 3y, 3x + 5y
#And in Python, my solution is: