#A solution to the Project Euler+ problem #2 on Hackerrank
This one uses Memoization so it's as efficient as possible. Unless it could be better! let me know!
## Example 5: Using memoization as decorator | |
class Memoize: | |
def __init__(self, fn): | |
self.fn = fn | |
self.memo = {} | |
def __call__(self, arg): | |
if arg not in self.memo: | |
self.memo[arg] = self.fn(arg) | |
return self.memo[arg] | |
##@Memoize | |
def fib(n): | |
a,b = 1,1 | |
for i in range(n-1): | |
a,b = b,a+b | |
return a | |
buff = int(input()) | |
for i in range(0,buff): | |
curr = int(input()) | |
j=0 | |
sum=0 | |
while fib(j) < curr : | |
if fib(j)%2 == 0: | |
sum+=fib(j) | |
j+=1 | |
print (str(sum)) |