AdventOfCode/Python/2024/11/main.py

31 lines
908 B
Python
Raw Normal View History

2024-12-10 21:24:00 -08:00
input = open("input", 'r').read().strip()
# d = [line for line in input]
# d = [[val for val in line.strip()] for line in input]
# d = {(complex(x,y)): int(c) for y,line in enumerate(input) for x,c in enumerate(line.strip())}
st = {int(s): 1 for s in input.split(" ")}
def blink(stone):
if stone == 0:
return [1]
strstone = str(stone)
ln = len(strstone)
if ln % 2 == 0:
return [int(strstone[ln//2:]), int(strstone[:ln//2])]
return [stone * 2024]
def run(stones, l=25):
for _ in range(l):
newstones = {}
for stone,total in stones.items():
for newstone in blink(stone):
if newstone in newstones:
newstones[newstone] += total
else:
newstones[newstone] = total
stones = newstones
return sum([ns for ns in stones.values()])
print(run(st))
print(run(st,75))