import time import copy start_time = time.time() with open('puzzle.txt', 'r') as f: line = f.read() stones = line.split(' ') for i in range(0, 25): loop_start = time.time() len_increased = 0 for index, stone in enumerate(copy.deepcopy(stones)): match stone: case '0': stones[index + len_increased] = '1' case stone if len(stone) % 2 == 0: divide_index = len(stone) // 2 first_half = str(int(stone[:divide_index])) second_half = str(int(stone[divide_index:])) stones[index + len_increased] = first_half stones.insert(index + len_increased + 1, second_half) len_increased += 1 case _: stones[index + len_increased] = str(int(stone) * 2024) print(f'loop {i} completed in {time.time() - start_time} seconds') print(len(stones)) print(f'Total time: {time.time() - start_time}')