moved to day11 directory
This commit is contained in:
1 parent
6adfe75f0e
commit
3d6e6397e1
3 files changed
+1
-1
No files matched your search
@@ -1 +0,0 @@
|
||||
814 1183689 0 1 766231 4091 93836 46
|
||||
@@ -1,43 +0,0 @@
|
||||
import functools
|
||||
|
||||
with open('input.text', 'r') as file:
|
||||
data = 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()))
|
||||
@@ -1 +0,0 @@
|
||||
125 17
|
||||
Reference in new issue
Block a user