Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day13(s, *, part2=False):
- values = np.array(
- [[re.findall(r'\d+', line) for line in s2.splitlines()] for s2 in s.split('\n\n')], int
- )
- b = values[:, 2][..., None] + (10_000_000_000_000 if part2 else 0)
- matrix = np.moveaxis(values[:, :2], 1, 2)
- x = np.linalg.solve(matrix, b)
- rounded = (x + 0.5).astype(int)
- solved = (matrix @ rounded == b).all(1)[:, 0]
- return np.sum(rounded[solved][..., 0] @ [3, 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement