This commit is contained in:
Stefan Harmuth 2024-12-11 07:20:30 +01:00
parent 9f259def72
commit 3ac9925c14
3 changed files with 46 additions and 0 deletions

44
day11.py Normal file
View File

@ -0,0 +1,44 @@
from tools.aoc import AOCDay
from tools.math import magnitude
from typing import Any
class Day(AOCDay):
inputs = [
[
(55312, "input11_test"),
(203228, "input11"),
],
[
(240884656550923, "input11"),
],
]
def iter_stone(self, stone: int, times: int) -> int:
if times == 0:
return 1
if (stone, times) in self.DP:
return self.DP[(stone, times)]
if stone == 0:
result = self.iter_stone(1, times - 1)
elif magnitude(stone) % 2 == 1:
div = magnitude(stone) // 2 + 1
result = self.iter_stone(stone % (10**div), times - 1) + self.iter_stone(stone // (10**div), times - 1)
else:
result = self.iter_stone(stone * 2024, times - 1)
self.DP[(stone, times)] = result
return result
def part1(self) -> Any:
return sum(self.iter_stone(x, 25) for x in map(int, self.getInput().split()))
def part2(self) -> Any:
return sum(self.iter_stone(x, 75) for x in map(int, self.getInput().split()))
if __name__ == "__main__":
day = Day(2024, 11)
day.run(verbose=True)

1
inputs/input11 Normal file
View File

@ -0,0 +1 @@
17639 47 3858 0 470624 9467423 5 188

1
inputs/input11_test Normal file
View File

@ -0,0 +1 @@
125 17