Files
aocpy/2024/d13.py
2024-12-13 00:58:31 -05:00

34 lines
783 B
Python

from lib import get_data
from lib import ints
data = get_data(__file__)
ps = data.split("\n\n")
c1, c2 = 0, 0
for p in ps:
lines = p.splitlines()
ax, ay = ints(lines[0])
bx, by = ints(lines[1])
px, py = ints(lines[2])
px2 = px + 10000000000000
py2 = py + 10000000000000
for a in range(0, 101):
for b in range(0, 101):
if a * ax + b * bx == px and a * ay + b * by == py:
c1 += a * 3 + b
D = ax * by - bx * ay
if abs(D) > 1e-10:
a_ = px2 * by - bx * py2
b_ = ax * py2 - px2 * ay
if a_ % D == 0 and b_ % D == 0:
a = (px2 * by - bx * py2) // D
b = (ax * py2 - px2 * ay) // D
if a >= 0 and b >= 0:
c2 += a * 3 + b
print(c1)
print(c2)