From 551d0b6018c054f891ffb3c3fb92a65e839c2d51 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Wed, 21 Dec 2022 09:50:39 +0100
Subject: whoo

---
 2022/19/input    | 30 ++++++++++++++++++++++++
 2022/19/solve.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 2022/19/input
 create mode 100644 2022/19/solve.py

(limited to '2022/19')

diff --git a/2022/19/input b/2022/19/input
new file mode 100644
index 0000000..17ddb86
--- /dev/null
+++ b/2022/19/input
@@ -0,0 +1,30 @@
+Blueprint 1: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 17 clay. Each geode robot costs 3 ore and 11 obsidian.
+Blueprint 2: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 12 obsidian.
+Blueprint 3: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 12 clay. Each geode robot costs 3 ore and 8 obsidian.
+Blueprint 4: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 8 clay. Each geode robot costs 2 ore and 10 obsidian.
+Blueprint 5: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 12 clay. Each geode robot costs 3 ore and 15 obsidian.
+Blueprint 6: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 5 clay. Each geode robot costs 4 ore and 8 obsidian.
+Blueprint 7: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 20 obsidian.
+Blueprint 8: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 13 clay. Each geode robot costs 2 ore and 9 obsidian.
+Blueprint 9: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 15 clay. Each geode robot costs 2 ore and 13 obsidian.
+Blueprint 10: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 3 ore and 8 obsidian.
+Blueprint 11: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 2 ore and 12 obsidian.
+Blueprint 12: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 17 clay. Each geode robot costs 3 ore and 11 obsidian.
+Blueprint 13: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 4 ore and 13 obsidian.
+Blueprint 14: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 3 ore and 16 obsidian.
+Blueprint 15: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 12 clay. Each geode robot costs 3 ore and 17 obsidian.
+Blueprint 16: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 2 ore and 11 obsidian.
+Blueprint 17: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 3 ore and 16 obsidian.
+Blueprint 18: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 19 clay. Each geode robot costs 2 ore and 12 obsidian.
+Blueprint 19: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 2 ore and 18 obsidian.
+Blueprint 20: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 3 ore and 17 obsidian.
+Blueprint 21: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 4 ore and 16 obsidian.
+Blueprint 22: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 16 clay. Each geode robot costs 3 ore and 20 obsidian.
+Blueprint 23: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 5 clay. Each geode robot costs 4 ore and 11 obsidian.
+Blueprint 24: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 4 ore and 12 obsidian.
+Blueprint 25: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 17 obsidian.
+Blueprint 26: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 11 clay. Each geode robot costs 2 ore and 7 obsidian.
+Blueprint 27: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 19 clay. Each geode robot costs 3 ore and 10 obsidian.
+Blueprint 28: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 4 ore and 8 obsidian.
+Blueprint 29: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 10 clay. Each geode robot costs 3 ore and 10 obsidian.
+Blueprint 30: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 7 clay. Each geode robot costs 4 ore and 11 obsidian.
diff --git a/2022/19/solve.py b/2022/19/solve.py
new file mode 100644
index 0000000..58310b5
--- /dev/null
+++ b/2022/19/solve.py
@@ -0,0 +1,69 @@
+import re
+from math import prod
+import functools
+
+all_costs = [
+    [(s[1], 0, 0, 0), (s[2], 0, 0, 0), (s[3], s[4], 0, 0), (s[5], 0, s[6], 0)]
+    for s in [
+        [int(x) for x in re.findall(r"\d+", dat)]
+        for dat in open("input").readlines()
+        if dat != ""
+    ]
+]
+
+
+def weight(state):  # from reddit, better than previously..
+    mined = state[-1][-1]
+    return 1000 * mined[3] + 100 * mined[2] + 10 * mined[1] + mined[0]
+
+
+@functools.lru_cache
+def bfs(current, bots, time_left, top):
+    costs = all_costs[current]
+    q = [(0, (bots, (0, 0, 0, 0), (0, 0, 0, 0)))]
+    res = 0
+    depth = 0
+    while q:
+        time, (bots, has, mined) = q.pop(0)
+
+        if time == time_left:
+            res = max(res, mined[3])
+            continue
+
+        if time > depth:
+            q.sort(key=weight, reverse=True)
+            q = q[:top]
+            depth = time
+
+        new_has = tuple(has[i] + bots[i] for i in range(4))
+        new_mined = tuple(mined[i] + bots[i] for i in range(4))
+
+        q.append((time + 1, (bots, new_has, new_mined)))
+
+        for i in range(4):
+            if any([has[j] < costs[i][j] for j in range(4)]):
+                continue
+
+            new_bots = bots[:i] + (bots[i] + 1,) + bots[(i + 1) :]
+            new_has_state = tuple(new_has[j] - costs[i][j] for j in range(4))
+            q.append((time + 1, (new_bots, new_has_state, new_mined)))
+    return res
+
+
+def part1():
+    return sum(
+        [
+            bfs(i, (1, 0, 0, 0), 24, 1000) * (i + 1)
+            for i in range(len(all_costs))
+        ]
+    )
+
+
+def part2():
+    return prod(
+        [bfs(i, (1, 0, 0, 0), 32, 10000) for i in range(len(all_costs[:3]))]
+    )
+
+
+print(f"Part 1: {part1()}")
+print(f"Part 2: {part2()}")
-- 
cgit v1.2.3