Advertisement
CrayonCrayoff

AoC 2024 Day 11 part 2

Dec 12th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import re
  2. from collections import defaultdict
  3.  
  4. with open("day11input.txt") as f:
  5.     input_nums = [int(x) for x in re.findall('\d+', f.read())]
  6.  
  7. stone_counts = defaultdict(int)
  8. for num in input_nums:
  9.     stone_counts[num] += 1
  10.  
  11. for _ in range(75):
  12.     new_stone_counts = defaultdict(int)
  13.     for stone, count in stone_counts.items():
  14.         if stone == 0:
  15.             new_stone_counts[1] += count
  16.         elif len(str(stone)) % 2 == 0:
  17.             str_rep = str(stone)
  18.             mid = len(str_rep) // 2
  19.             new_stone_counts[int(str_rep[mid:])] += count
  20.             new_stone_counts[int(str_rep[:mid])] += count
  21.         else:
  22.             new_stone_counts[stone * 2024] += count
  23.     stone_counts = new_stone_counts
  24.  
  25. print(sum(stone_counts.values()))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement