summary refs log tree commit diff
path: root/22.11/main.py
diff options
context:
space:
mode:
authordzwdz2022-12-11 14:08:57 +0100
committerdzwdz2022-12-11 14:08:57 +0100
commit8dcd40b1b2f349d2f22a18c4f25b9975bf976f88 (patch)
treef7e4d2c21a6b745266762171bcb263efe2cf8ee1 /22.11/main.py
parent1481706ee8299b9e10004c776d6b5a709246b622 (diff)
day 11 part 1
Diffstat (limited to '22.11/main.py')
-rw-r--r--22.11/main.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/22.11/main.py b/22.11/main.py
new file mode 100644
index 0000000..f4ac1fb
--- /dev/null
+++ b/22.11/main.py
@@ -0,0 +1,51 @@
+items = []
+ops = []
+decide = []
+points = []
+
+# 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:])
+
+	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
+
+def doRound():
+	for monkey in range(len(items)):
+		points[monkey] += len(items[monkey])
+		for item in items[monkey]:
+			item = ops[monkey](item) // 3
+			items[decide[monkey](item)].append(item)
+		items[monkey] = []
+
+for _ in range(20):
+	doRound()
+
+a, b = sorted(points)[-2:]
+print(a * b)