diff options
author | Santo Cariotti <sancn@live.com> | 2017-04-26 16:38:35 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-04-26 16:38:35 +0200 |
commit | 3edad98480ba30557a3fabac2d2ff325e91c6ea3 (patch) | |
tree | ff5e9118063c744b9b977f606f8a829681926bb4 /python/lswf.py | |
parent | 0cd87bbb7fbd3c75c902eb287596b131cdfdebdf (diff) |
Moved all python files into a folder
Diffstat (limited to 'python/lswf.py')
-rw-r--r-- | python/lswf.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/python/lswf.py b/python/lswf.py new file mode 100644 index 0000000..7a309ad --- /dev/null +++ b/python/lswf.py @@ -0,0 +1,41 @@ +fib = [] +fib.append(1) +fib.append(1) + +def fibonacci(N): + for i in range(2, N): + fib.append(fib[i - 1] + fib[i - 2]) + + if fib[i] > N: + break + + return i + + +with open('input.txt', 'r') as fin: + N = int(fin.readline()) + +lst = fibonacci(N) + +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)) |