diff --git a/src/holt59/aoc/2024/day11.py b/src/holt59/aoc/2024/day11.py index 07e201e..fea35bf 100644 --- a/src/holt59/aoc/2024/day11.py +++ b/src/holt59/aoc/2024/day11.py @@ -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) diff --git a/src/holt59/aoc/inputs/holt59/2024/day11.txt b/src/holt59/aoc/inputs/holt59/2024/day11.txt index e69de29..4c7941d 100644 --- a/src/holt59/aoc/inputs/holt59/2024/day11.txt +++ b/src/holt59/aoc/inputs/holt59/2024/day11.txt @@ -0,0 +1 @@ +2 77706 5847 9258441 0 741 883933 12 diff --git a/src/holt59/aoc/inputs/tests/2024/day11.txt b/src/holt59/aoc/inputs/tests/2024/day11.txt index e69de29..9b26c84 100644 --- a/src/holt59/aoc/inputs/tests/2024/day11.txt +++ b/src/holt59/aoc/inputs/tests/2024/day11.txt @@ -0,0 +1 @@ +125 17