My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2024/11

+27
+27
2024/day11.py
··· 1 + import fileinput 2 + from collections import Counter 3 + 4 + 5 + stones = Counter(int(n) for n in fileinput.input()[0].split()) 6 + 7 + for blink in range(1, 76): 8 + new_stones = Counter() 9 + for stone, count in stones.items(): 10 + stone_str = str(stone) 11 + 12 + if stone == 0: 13 + new_stones[1] += count 14 + elif len(stone_str) % 2 == 0: 15 + mid = len(stone_str) // 2 16 + left, right = stone_str[:mid], stone_str[mid:] 17 + new_stones[int(left)] += count 18 + new_stones[int(right)] += count 19 + else: 20 + new_stones[stone * 2024] += count 21 + 22 + stones = new_stones 23 + 24 + if blink == 25: 25 + print("Part 1:", sum(stones.values())) 26 + elif blink == 75: 27 + print("Part 2:", sum(stones.values()))