Skip to content

Problem 234 project Euler #883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 16, 2019
31 changes: 31 additions & 0 deletions project_euler/problem_234.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# https://projecteuler.net/problem=234
def fib(a, b, n):
temp = 0
if n==1:
return a
elif n==2:
return b
elif n==3:
return str(a)+str(b)
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this else could be ignore. Because never will be go to else if return occur before. (Just a comment)

and temp=0 could be defined after the ifs. This way we could avoid use memory when is not necessary.

for x in range(2,n):
c=str(a) + str(b)
temp = b
b = c
a = temp
return c


q=int(input())
for x in range(q):
l=[i for i in input().split()]
c1=0
c2=1
while(1):

if len(fib(l[0],l[1],c2))<int(l[2]):
c2+=1
else:
break
print(fib(l[0],l[1],c2+1)[int(l[2])-1])