aboutsummaryrefslogtreecommitdiff
path: root/2024/11
diff options
context:
space:
mode:
authorMarvin Borner2024-12-11 17:37:29 +0100
committerMarvin Borner2024-12-11 17:37:29 +0100
commitee9ab89acf59028e1bd0d4e15ae8f981ed172533 (patch)
treece55c92e0ffa32b789069a44288e331f6de5a90a /2024/11
parent299e8190b151d85423cb461f4bc31d1c881fad84 (diff)
woah i'm back
Diffstat (limited to '2024/11')
-rwxr-xr-x2024/11/solve.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/2024/11/solve.py b/2024/11/solve.py
new file mode 100755
index 0000000..55cc50d
--- /dev/null
+++ b/2024/11/solve.py
@@ -0,0 +1,34 @@
+#!/bin/env python
+
+stones = [int(d) for d in open("input").read().strip().split(" ")]
+
+cache = {}
+
+
+def solve(n, stone):
+ if n == 0:
+ return 1
+
+ if (n, stone) in cache:
+ return cache[(n, stone)]
+
+ sstone = str(stone)
+ if stone == 0:
+ res = solve(n - 1, 1)
+ elif len(sstone) % 2 == 0:
+ left = solve(n - 1, int(sstone[: len(sstone) // 2]))
+ right = solve(n - 1, int(sstone[len(sstone) // 2 :]))
+ res = left + right
+ else:
+ res = solve(n - 1, stone * 2024)
+
+ cache[(n, stone)] = res
+ return res
+
+
+part1 = 0
+part2 = 0
+for stone in stones:
+ part1 += solve(25, stone)
+ part2 += solve(75, stone)
+print(part1, part2)