1
0
Fork 0

05: Python: Faster

This commit is contained in:
Mia Herkt 2022-12-06 16:10:45 +01:00
parent 5c8be75eee
commit cbb0c57d81
Signed by: mia
GPG Key ID: 72E154B8622EC191
1 changed files with 8 additions and 8 deletions

View File

@ -14,16 +14,16 @@ for l in sys.stdin:
for i, c in enumerate(l[1::4], 1):
if c != ' ':
c = ord(c)
stacksA[i].append(c)
stacksB[i].append(c)
stacksA[i].insert(0, c)
stacksB[i].insert(0, c)
im = insr.match(l)
if im:
n, f, t = map(int, im.groups())
stacksA[t] = bytearray(reversed(stacksA[f][:n])) + stacksA[t]
stacksA[f] = stacksA[f][n:]
stacksB[t] = stacksB[f][:n] + stacksB[t]
stacksB[f] = stacksB[f][n:]
stacksA[t] += stacksA[f][-n:][::-1]
stacksA[f] = stacksA[f][:-n]
stacksB[t] += stacksB[f][-n:]
stacksB[f] = stacksB[f][:-n]
print(f"""Silver: {"".join(chr(stacksA[i][0]) for i in sorted(stacksA))}
Gold: {"".join(chr(stacksB[i][0]) for i in sorted(stacksB))}""")
print(f"""Silver: {"".join(chr(stacksA[i][-1]) for i in sorted(stacksA))}
Gold: {"".join(chr(stacksB[i][-1]) for i in sorted(stacksB))}""")