Advertisement
hhoppe

Advent of code 2024 day 17 part 2

Dec 18th, 2024 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. def day17_part2(s):
  2.   program = list(map(int, s.split('Program: ')[1].split(',')))
  3.   k1, k2 = (program[i + 1] for i in range(0, len(program), 2) if program[i] == 1)  # 'bst' params.
  4.  
  5.   def explore(a, values):
  6.     if not values:
  7.       return a
  8.     solutions = (
  9.         explore(a * 8 + b, values[1:])
  10.         for b in range(8)
  11.         if (b ^ k1 ^ k2 ^ ((a * 8 + b) >> (b ^ k1))) & 7 == values[0]
  12.     )
  13.     return min(solutions, default=1 << 62)
  14.  
  15.   return explore(0, program[::-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement