Find the number of Fibonacci numbers F i such that 1 2 3 4 5 6 7 8 9 0 ≤ F i ≤ 9 8 7 6 5 4 3 2 1 0 .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
def fib(n):
f1=1
f2=1
if n==1 or n==2:
return 1
else:
for i in range(3,n+1):
f1,f2=f2,f1+f2
return f2
count=0
for i in range(1,200):
if fib(i)>=1234567890 and fib(i)<=9876543210:
count+=1
print count
My code:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Solution using Haskell:
1 2 3 |
|
So the answer is 4
Here is how I coded it up
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Welcome back,sir!!
Log in to reply
Thanks! :)
Problem Loading...
Note Loading...
Set Loading...
phi = (1 + 5**0.5) / 2
Not that elegant but very fast code.....