summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-23 19:43:32 +0200
committerGitHub <noreply@github.com>2017-04-23 19:43:32 +0200
commite1d76dd1d6e9cd35a17e6443d7222a9499ccc698 (patch)
tree5b8df0d8e293a0f280bfd30f6105c95a987ef5fd
parent8317eb9cae7ff46e400534572542496fef508cfc (diff)
Update lswf.py
-rw-r--r--lswf.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/lswf.py b/lswf.py
index 29d58b2..cc51cb7 100644
--- a/lswf.py
+++ b/lswf.py
@@ -1,23 +1,20 @@
fib = [1, 1]
-lst = 0
def fibonacci(N):
- global lst
for i in range(2, N):
fib.append(fib[i - 1] + fib[i - 2])
- lst = i
+
if fib[i] > N:
break
+
+ return i
with open('input.txt', 'r') as fin:
N = int(fin.readline())
-fibonacci(N)
-
-for i in fib:
- print(i, end=' ')
+lst = fibonacci(N)
fib.reverse()
print()
@@ -40,4 +37,4 @@ if N == 1 or N > 4:
with open('output.txt', 'w') as fout:
for i in seq:
- fout.write(str(i)) \ No newline at end of file
+ fout.write(str(i))