This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
ProgrammingChallenges/getting_digits.py
2019-04-22 18:40:44 +02:00

71 lines
1.6 KiB
Python
Executable file

def get_digits(s):
S = ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
"EIGHT", "NINE"]
L = {
'A': [],
'B': [],
'C': [],
'D': [],
'E': [0,1,3,5,7,8,9], #3*2 7*2
'F': [4,5],
'G': [8],
'H': [3,8],
'I': [5,6,8,9],
'J': [],
'K': [],
'L': [],
'M': [],
'N': [1,7,9], #9*2
'O': [0,1,2,4],
'P': [],
'Q': [],
'R': [0,3,4],
'S': [6,7],
'T': [2,3,8],
'U': [4],
'V': [5,7],
'W': [2],
'X': [6],
'Y': [],
'Z': [0]
}
dgts = [0] * 10
O = []
N = []
for string in S:
O.append(list(string))
N.append(list(string))
removed = []
for c in s:
print(c)
for n in L[c]:
try:
N[n].remove(c)
removed.append([n, c])
except ValueError:
"fregacazzi"
print(N)
for i in range(10):
if len(N[i]) == 0:
print("BINGO "+ str(i))
dgts[i] = dgts[i] + 1
for log in reversed(removed):
if log[1] in O[i]:
N[log[0]].append(log[1])
del log
print(N)
print(dgts)
print(N)
o = ""
for i in range(10):
while dgts[i] > 0:
o = o + str(i)
dgts[i] = dgts[i] - 1
return o
if __name__ == "__main__":
n = int(input())
for i in range(1, n + 1):
print("Case #" + str(i) + ": " + get_digits(input()))