summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-12-10 23:52:20 -0700
committerJack Sangdahl <[email protected]>2024-12-10 23:52:20 -0700
commit6dcf66699c5790aa81ec11f9c40ea6b4b1dab029 (patch)
tree3e906a0dc664a6cfa38ec9576dadede3627608f0
parentf58fe1976f49eefc8d06b7806e00cfcde2647af4 (diff)
downloadaoc-6dcf66699c5790aa81ec11f9c40ea6b4b1dab029.tar.gz
aoc-6dcf66699c5790aa81ec11f9c40ea6b4b1dab029.zip
Day 11 2024
-rw-r--r--11_2024.py31
-rw-r--r--data/11_2024.txt1
2 files changed, 32 insertions, 0 deletions
diff --git a/11_2024.py b/11_2024.py
new file mode 100644
index 0000000..a67f8cf
--- /dev/null
+++ b/11_2024.py
@@ -0,0 +1,31 @@
+input = "data/11_2024.txt"
+data = open(input).read().strip()
+data = [int(x) for x in data.split()]
+dp = {}
+
+
+def solve(x, t):
+ if (x, t) in dp:
+ return dp[(x, t)]
+ if t == 0:
+ res = 1
+ elif x == 0:
+ res = solve(1, t - 1)
+ elif len(str(x)) % 2 == 0:
+ dstr = str(x)
+ left = dstr[: len(dstr) // 2]
+ right = dstr[len(dstr) // 2 :]
+ left, right = (int(left), int(right))
+ res = solve(left, t - 1) + solve(right, t - 1)
+ else:
+ res = solve(x * 2024, t - 1)
+ dp[(x, t)] = res
+ return res
+
+
+def solve_all(t):
+ return sum(solve(x, t) for x in data)
+
+
+print(solve_all(25))
+print(solve_all(75))
diff --git a/data/11_2024.txt b/data/11_2024.txt
new file mode 100644
index 0000000..e029d56
--- /dev/null
+++ b/data/11_2024.txt
@@ -0,0 +1 @@
+5688 62084 2 3248809 179 79 0 172169