Solve 2024 day 13
This commit is contained in:
parent
efb1e3e551
commit
3432d81941
33
2024/d13.py
Normal file
33
2024/d13.py
Normal file
@ -0,0 +1,33 @@
|
||||
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)
|
@ -303,5 +303,6 @@ and focus. Of course, learning more algorithms and techniques helps.
|
||||
- Day 10: `00:19:47 2976 0 00:20:47 2244 0`
|
||||
- Day 11: `00:05:13 642 0 00:33:07 2673 0`
|
||||
- Day 12: `00:30:30 3540 0 11:41:33 16212 0`
|
||||
- Day 13:
|
||||
- Day 13: `00:05:35 225 0 00:55:48 2544 0`
|
||||
- Day 14:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user