Spaces:
Running
Running
File size: 1,049 Bytes
a4da721 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
def transform_stones(stones):
new_stones = []
for stone in stones:
if stone == 0:
new_stones.append(1)
elif len(str(stone)) % 2 == 0:
# Split the stone
str_stone = str(stone)
mid = len(str_stone) // 2
left = int(str_stone[:mid])
right = int(str_stone[mid:])
new_stones.extend([left, right])
else:
# Multiply by 2024
new_stones.append(stone * 2024)
return new_stones
def simulate_blinks(initial_stones, blinks):
stones = initial_stones
for _ in range(blinks):
stones = transform_stones(stones)
return stones
# Read input from file
file = "input.txt"
with open(file, "r") as f:
initial_stones = list(map(int, f.read().strip().split()))
# Part 1: After 25 blinks
stones_after_25_blinks = simulate_blinks(initial_stones, 25)
print(len(stones_after_25_blinks))
# Part 2: After 75 blinks
stones_after_75_blinks = simulate_blinks(initial_stones, 75)
print(len(stones_after_75_blinks)) |