2024 day 11.
This commit is contained in:
parent
22129048e7
commit
92bd85e1dd
@ -1,7 +1,29 @@
|
|||||||
|
from functools import cache
|
||||||
from typing import Any, Iterator
|
from typing import Any, Iterator
|
||||||
|
|
||||||
from ..base import BaseSolver
|
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):
|
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)
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
2 77706 5847 9258441 0 741 883933 12
|
@ -0,0 +1 @@
|
|||||||
|
125 17
|
Loading…
Reference in New Issue
Block a user