File size: 967 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
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()