advent-of-code/2024/day13/day13.bqn
2024-12-13 20:40:21 +01:00

20 lines
667 B
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

lf,Split•Import"../bqn-libs/strings.bqn"
in>•ParseFloat¨¨¨2¨¨¨", "Split¨¨1¨¨": "Split¨¨lfSplit¨(lflf)Split ¯1•FChars"input"
Solve{offset𝕊xaya,xbyb,xpyp:
xpyp+offset
nanb{
# A and B are collinear, we should find the optimal solution,
# but I didn't need it for my input
𝕊0: 00;
# General case
nb((xp×ya)-yp×xa)÷𝕩
na(xp-nb×xb)÷xa
# Check that solution is integer
{´=𝕩 ? 𝕩 ; 00}nanb
}(xb×ya)-yb×xa
}
•Show +´+˝31ע0Solve˘in
•Show +´+˝31ע10000000000000Solve˘in