1
0
Fork 0

11: Py: Just use lists to hold items

This commit is contained in:
Mia Herkt 2022-12-11 19:51:34 +01:00
parent 7b51b5820b
commit 0a9f3c078d
Signed by: mia
GPG key ID: 72E154B8622EC191

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python3
import sys
from collections import deque
from copy import deepcopy
from math import prod
@ -13,7 +12,7 @@ for l in sys.stdin:
monkeys.append({})
monkeys[-1]["count"] = 0
elif l.startswith("S"):
monkeys[-1]["items"] = deque(int(x) for x in l[16:].split(", "))
monkeys[-1]["items"] = [int(x) for x in l[16:].split(", ")]
elif l.startswith("O"):
monkeys[-1]["op"] = l[17:]
elif l.startswith("T"):
@ -27,20 +26,20 @@ monkeysG = deepcopy(monkeys)
for it in range(20):
for m in monkeys:
while len(m["items"]):
for old in m["items"]:
m["count"] += 1
old = m["items"].popleft()
new = eval(m["op"]) // 3
monkeys[m[not (new % m["test"])]]["items"].append(new)
m["items"].clear()
ohmygodihateyoueric = prod(m["test"] for m in monkeys)
for it in range(10000):
for m in monkeysG:
while len(m["items"]):
for old in m["items"]:
m["count"] += 1
old = m["items"].popleft()
new = eval(m["op"]) % ohmygodihateyoueric
monkeysG[m[not (new % m["test"])]]["items"].append(new)
m["items"].clear()
resS = sorted(m["count"] for m in monkeys)[-2:]
resG = sorted(m["count"] for m in monkeysG)[-2:]