Advertisement
hhoppe

Advent of code 2024 day 13

Dec 13th, 2024 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. def day13(s, *, part2=False):
  2.   total = 0
  3.   for s2 in s.split('\n\n'):
  4.     values = np.array([re.findall(r'\d+', line) for line in s2.splitlines()], int)
  5.     if part2:
  6.       values[2] += 10_000_000_000_000
  7.     x = sympy.Matrix(values[:2].T).LUsolve(sympy.Matrix(values[2]))
  8.     if all(elem.is_Integer for elem in x):
  9.       total += x[0] * 3 + x[1]
  10.  
  11.   return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement