advent-of-code/2024/11/one.py
2024-12-25 12:59:49 +01:00

31 lines
735 B
Python

#!/usr/bin/env python3
import sys
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
height = len(lines)
width = len(lines[0])
stones = [int(stone) for stone in lines[0].split()]
for _ in range(25):
new_stones = []
for stone in stones:
stone_str = str(stone)
if stone == 0:
new_stones.append(1)
elif len(stone_str) % 2 == 0:
mid = int(len(stone_str) / 2)
new_stones.append(int(stone_str[:mid]))
new_stones.append(int(stone_str[mid:]))
else:
new_stones.append(stone * 2024)
stones = new_stones
# print(" ".join(str(stone) for stone in stones))
print(len(stones))