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
|
||||||
|
|
1279
2024/day13/input
Normal file
1279
2024/day13/input
Normal file
File diff suppressed because it is too large
Load diff
15
2024/day13/test
Normal file
15
2024/day13/test
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Button A: X+94, Y+34
|
||||||
|
Button B: X+22, Y+67
|
||||||
|
Prize: X=8400, Y=5400
|
||||||
|
|
||||||
|
Button A: X+26, Y+66
|
||||||
|
Button B: X+67, Y+21
|
||||||
|
Prize: X=12748, Y=12176
|
||||||
|
|
||||||
|
Button A: X+17, Y+86
|
||||||
|
Button B: X+84, Y+37
|
||||||
|
Prize: X=7870, Y=6450
|
||||||
|
|
||||||
|
Button A: X+69, Y+23
|
||||||
|
Button B: X+27, Y+71
|
||||||
|
Prize: X=18641, Y=10279
|
Loading…
Add table
Add a link
Reference in a new issue