day 11: explore recursively, use cache
This commit is contained in:
parent
4aa762f073
commit
422e5440ff
|
@ -0,0 +1,21 @@
|
||||||
|
import sys
|
||||||
|
from math import log10
|
||||||
|
from functools import cache
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def mutate(n:int, t:int) -> int:
|
||||||
|
if t == 0:
|
||||||
|
return 1
|
||||||
|
if n == 0:
|
||||||
|
return mutate(1, t-1)
|
||||||
|
if (digits := int(log10(n))+1) & 1 == 0:
|
||||||
|
return count(divmod(n, 10**(digits//2)), t-1)
|
||||||
|
return mutate(n*2024, t-1)
|
||||||
|
|
||||||
|
def count(stones: list[int], times: int) -> int:
|
||||||
|
return sum(mutate(stone, times) for stone in stones)
|
||||||
|
|
||||||
|
stones = [int(n) for n in sys.stdin.read().strip().split(" ")]
|
||||||
|
|
||||||
|
print(count(stones, 25))
|
||||||
|
print(count(stones, 75))
|
Loading…
Reference in New Issue