Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from collections import defaultdict
- with open("day11input.txt") as f:
- input_nums = [int(x) for x in re.findall('\d+', f.read())]
- stone_counts = defaultdict(int)
- for num in input_nums:
- stone_counts[num] += 1
- for _ in range(75):
- new_stone_counts = defaultdict(int)
- for stone, count in stone_counts.items():
- if stone == 0:
- new_stone_counts[1] += count
- elif len(str(stone)) % 2 == 0:
- str_rep = str(stone)
- mid = len(str_rep) // 2
- new_stone_counts[int(str_rep[mid:])] += count
- new_stone_counts[int(str_rep[:mid])] += count
- else:
- new_stone_counts[stone * 2024] += count
- stone_counts = new_stone_counts
- print(sum(stone_counts.values()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement