From 3edad98480ba30557a3fabac2d2ff325e91c6ea3 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 26 Apr 2017 16:38:35 +0200 Subject: Moved all python files into a folder --- lswf.py | 41 ----------------------------------------- python/lswf.py | 41 +++++++++++++++++++++++++++++++++++++++++ python/scommesse.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ scommesse.py | 50 -------------------------------------------------- 4 files changed, 91 insertions(+), 91 deletions(-) delete mode 100644 lswf.py create mode 100644 python/lswf.py create mode 100644 python/scommesse.py delete mode 100644 scommesse.py diff --git a/lswf.py b/lswf.py deleted file mode 100644 index 7a309ad..0000000 --- a/lswf.py +++ /dev/null @@ -1,41 +0,0 @@ -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)) 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)) diff --git a/python/scommesse.py b/python/scommesse.py new file mode 100644 index 0000000..b947df1 --- /dev/null +++ b/python/scommesse.py @@ -0,0 +1,50 @@ +carteV = [] +carteOut = [] + + +def cOutPresente(x): + s = False + for i in range(len(carteOut)): + if (carteOut[i] == x): + s = True + + if not s: + carteOut.append(x) + + +def fCarte(N, start): + c = carteV[:] + + while len(c) > 1: + tot = len(c) + for i in range(start, tot - 1): + x = c[i] + x1 = c[i + 1] + x2 = x + x1 + + if ((x2 % 2) != 0): + c.remove(x) + c.remove(x1) + break + + start = 0 + + cOutPresente(c[0]) + + +with open('input.txt', 'r') as fin: + N = int(fin.readline()) + carteV = fin.readline().split(' ') + +for i in range(N): + carteV[i] = int(carteV[i]) + +for i in range(N): + fCarte(N, start=i) + +with open('output.txt', 'w') as fout: + fout.write(str(len(carteOut))) + fout.write('\n') + + for i in carteOut: + fout.write(str(i) + ' ') diff --git a/scommesse.py b/scommesse.py deleted file mode 100644 index b947df1..0000000 --- a/scommesse.py +++ /dev/null @@ -1,50 +0,0 @@ -carteV = [] -carteOut = [] - - -def cOutPresente(x): - s = False - for i in range(len(carteOut)): - if (carteOut[i] == x): - s = True - - if not s: - carteOut.append(x) - - -def fCarte(N, start): - c = carteV[:] - - while len(c) > 1: - tot = len(c) - for i in range(start, tot - 1): - x = c[i] - x1 = c[i + 1] - x2 = x + x1 - - if ((x2 % 2) != 0): - c.remove(x) - c.remove(x1) - break - - start = 0 - - cOutPresente(c[0]) - - -with open('input.txt', 'r') as fin: - N = int(fin.readline()) - carteV = fin.readline().split(' ') - -for i in range(N): - carteV[i] = int(carteV[i]) - -for i in range(N): - fCarte(N, start=i) - -with open('output.txt', 'w') as fout: - fout.write(str(len(carteOut))) - fout.write('\n') - - for i in carteOut: - fout.write(str(i) + ' ') -- cgit v1.2.3-18-g5258