2024 day 13
This commit is contained in:
parent
bea330905c
commit
e479454d81
3 changed files with 1314 additions and 0 deletions
20
2024/day13/day13.bqn
Normal file
20
2024/day13/day13.bqn
Normal file
|
@ -0,0 +1,20 @@
|
|||
⟨lf,Split⟩←•Import"../bqn-libs/strings.bqn"
|
||||
in←>•ParseFloat¨¨¨2⊸↓¨¨¨", "⊸Split¨¨1⊸⊑¨¨": "⊸Split¨¨lf⊸Split¨(lf∾lf)Split ¯1↓•FChars"input"
|
||||
|
||||
Solve←{offset𝕊⟨xa‿ya,xb‿yb,xp‿yp⟩:
|
||||
xp‿yp+↩offset
|
||||
na‿nb←{
|
||||
# A and B are collinear, we should find the optimal solution,
|
||||
# but I didn't need it for my input
|
||||
𝕊0: 0‿0;
|
||||
# General case
|
||||
nb←((xp×ya)-yp×xa)÷𝕩
|
||||
na←(xp-nb×xb)÷xa
|
||||
# Check that solution is integer
|
||||
{∧´⌊⊸=𝕩 ? 𝕩 ; 0‿0}na‿nb
|
||||
}(xb×ya)-yb×xa
|
||||
}
|
||||
|
||||
•Show +´+˝3‿1⊸ע0⊸Solve˘in
|
||||
•Show +´+˝3‿1⊸ע10000000000000⊸Solve˘in
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue