Spaces:
Running
Running
def solve(): | |
with open("./input.txt", "r") as f: | |
initial_stones = [int(x) for x in f.readline().split()] | |
def blink(stones): | |
new_stones = [] | |
for stone in stones: | |
if stone == 0: | |
new_stones.append(1) | |
elif len(str(stone)) % 2 == 0: | |
s = str(stone) | |
mid = len(s) // 2 | |
left = int(s[:mid]) | |
right = int(s[mid:]) | |
new_stones.append(left) | |
new_stones.append(right) | |
else: | |
new_stones.append(stone * 2024) | |
return new_stones | |
# Part 1: 25 blinks | |
stones = initial_stones[:] # Create a copy to avoid modifying the original | |
for _ in range(25): | |
stones = blink(stones) | |
print(len(stones)) | |
# Part 2: 75 blinks | |
stones = initial_stones[:] # Reset to the initial state | |
for _ in range(75): | |
stones = blink(stones) | |
print(len(stones)) | |
solve() |