moved to day11 directory

This commit is contained in:
JISAUAY committed 2025-03-05 16:32:53 -06:00
1 parent 6adfe75f0e
commit 3d6e6397e1
3 files changed
+1 -1

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import functools
with open('input.text', 'r') as file:
data: str = file.read()
stones: dict[int, int] = {}
for n in data.split():
n = int(n)
if n not in stones:
stones[n] = 1
else:
stones[n] += 1
blinks = 75
@functools.cache
def process_stone(n: int) -> list[int]:
if n == 0:
return [1]
elif (digits := len(str(n))) % 2 == 0:
split: int = digits // 2
return [int(str(n)[:split]), int(str(n)[split:])]
else:
return [n * 2024]
def blink(stones: dict[int, int]) -> dict[int, int]:
counts: dict[int, int] = {}
for n, count in stones.items():
new_stones: list[int] = process_stone(n)
for new_stone in new_stones:
if new_stone not in counts:
counts[new_stone] = count
else:
counts[new_stone] += count
return counts
for i in range(blinks):
stones = blink(stones)
print(i + 1, sum(stones.values()))