summary refs log tree commit diff
path: root/22.11/part2.py
blob: 08821fd938604fe3581bfc07d2556fbae8888e0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from functools import reduce

items = []
ops = []
decide = []
points = []
tests = []

# garbage parser because i fucking hate this day already
def readMonke():
	input()
	items.append([int(s) for s in input()[18:].split(', ')])

	op_l = input()[23:]
	op = op_l[0]
	arg = None
	self = op_l[2:] == "old"
	if not self:
		arg = int(op_l[2:])

	if self and op == "*":
		ops.append(lambda x: x * x)
	elif not self and op == "*":
		ops.append(lambda x: x * arg)
	elif not self and op == "+":
		ops.append(lambda x: x + arg)
	else:
		raise "fuck shit piss"

	test = int(input()[21:])
	tests.append(test)

	onTrue = int(input()[29:])
	onFalse = int(input()[30:])
	decide.append(lambda x: onTrue if x % test == 0 else onFalse)
	points.append(0)

while True:
	readMonke()
	try: input()
	except EOFError: break

lcm = reduce(lambda a,b:a*b, tests) # all prime numbers, no lcm on town

def doRound():
	for monkey in range(len(items)):
		points[monkey] += len(items[monkey])
		for item in items[monkey]:
			item = ops[monkey](item) % lcm
			items[decide[monkey](item)].append(item)
		items[monkey] = []


for _ in range(10000):
	doRound()

a, b = sorted(points)[-2:]
print(a * b)