summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-23 09:41:26 +0200
committerGitHub <noreply@github.com>2017-04-23 09:41:26 +0200
commitaf941bef2050f63e110ca30025142b33a6ef7326 (patch)
tree70bdca93c531f371590c3e8f19b89a43c333f1c2
parent06399f5279df8c9fb8f4c8451daf87653b26cc8d (diff)
LSWF in Python
-rw-r--r--lswf.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/lswf.py b/lswf.py
new file mode 100644
index 0000000..29d58b2
--- /dev/null
+++ b/lswf.py
@@ -0,0 +1,43 @@
+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
+
+
+with open('input.txt', 'r') as fin:
+ N = int(fin.readline())
+
+fibonacci(N)
+
+for i in fib:
+ print(i, end=' ')
+
+fib.reverse()
+print()
+
+somma = 0
+seq = []
+for i in range(0,len(fib)-1):
+ potSomma = somma + fib[i]
+ if potSomma < N:
+ somma = potSomma
+ seq.append(1)
+ else:
+ seq.append(0)
+
+seq.append(1)
+seq.reverse()
+
+if N == 1 or N > 4:
+ seq.pop()
+
+with open('output.txt', 'w') as fout:
+ for i in seq:
+ fout.write(str(i)) \ No newline at end of file