blob: 55cc50dd1cafdde91d7f4ba22ca213d82012b282 (
plain) (
blame)
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
|
#!/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)
|