Uiua
Not really proud of this one. Part 1's still ok, just calculated all distances between boxes after realizing it's not that many (499500, a reasonable amount I think, relatively speaking).
The dumbest thing I did this time was manually implementing the function to take the first n rows of an array by using a loop. Only when I was working on part 2 did I realize that I can just use the "take" function Uiua provides. Additionally, I even had some mistake in my reimplementation of it that only caused issues in part 2 somehow.
For anyone interested, it's the commented out line in Pβ below.
Part 2 is just a brute force. For the actual input, I searched manually until I got to the pair number just before the actual solution because I didn't want it to run that long and it takes long enough as is.
Code
$ 162,817,812
$ 57,618,57
$ 906,360,560
$ 592,479,940
$ 352,342,300
$ 466,668,158
$ 542,29,236
$ 431,825,988
$ 739,650,466
$ 52,470,668
$ 216,146,977
$ 819,987,18
$ 117,168,530
$ 805,96,715
$ 346,949,466
$ 970,615,88
$ 941,993,340
$ 862,61,35
$ 984,92,344
$ 425,690,689
Dist β β(β‘Β°β)/+β΅-Β°β
Prep β (
β(βββΈβ @,)βΈβ @\n
β§
<2
βββΈβ‘Dist
)
Merge β (
ββββ
{}
β₯(β£(β(Β°β
β‘β₯(
ββΈΛβ‘β(>/+ββ¨(Γββ
β§»))
β΄ββ(ββ©ββ½βΒ¬)
)β
)
β
| β)
)β
ββ
)
Pβ β (
Prep
# β₯ββ(ββ€β‘Β°Λβ)
βββ
Merge
ββ‘ββ§»
/Γβββ
)
Pβ β (
Prep
1_0
βΈβ’(
βΒ°Λβ(
β+β
β
ββ
β(Merge
ββ§»β’)
)
| <20β£)
-ββ’
β‘
ΓΒ°ββ‘ββ
)
[βPβPβ]
β‘(&p $"Part _: _") 1_2