2024 day 11.

This commit is contained in:
Mikaël Capelle 2024-12-11 07:13:28 +01:00
parent 22129048e7
commit 92bd85e1dd
3 changed files with 25 additions and 1 deletions

View File

@ -1,7 +1,29 @@
from functools import cache
from typing import Any, Iterator
from ..base import BaseSolver
@cache
def blink_one_stone(stone: int, round: int) -> int:
if round == 0:
return 1
if stone == 0:
return blink_one_stone(1, round - 1)
if len((stone_s := str(stone))) % 2 == 0:
n = len(stone_s)
return blink_one_stone(int(stone_s[: n // 2]), round - 1) + blink_one_stone(
int(stone_s[n // 2 :]), round - 1
)
return blink_one_stone(stone * 2024, round - 1)
class Solver(BaseSolver):
def solve(self, input: str) -> Iterator[Any]: ...
def solve(self, input: str) -> Iterator[Any]:
stones = list(map(int, input.split()))
yield sum(blink_one_stone(stone, 25) for stone in stones)
yield sum(blink_one_stone(stone, 75) for stone in stones)

View File

@ -0,0 +1 @@
2 77706 5847 9258441 0 741 883933 12

View File

@ -0,0 +1 @@
125 17