3 4
4 3
2 5
1 3
3 9
3 3
- get left and right lists from the input
- sort each list into numerical order
- find the sum of the differences between each pair of numbers
if the input is
[3 4 2 1 3 3]
[4 3 5 3 9 3]
then we want to sort each array into order
⍆:⍆
sort flip sort
which gives
[3 3 3 4 5 9]
[1 2 3 3 3 4]
(no need to flip back as we only care about differences)
then just subtract one array from the other, absolute value everything to get distances, and add up
/+⌵-
reduce add abs subtract
📩 ← /+⌵-⍆:⍆
&fras
file - read all to string
⊜□¬ ⊸⌕ "\n"
partition box not by find "\n"- splits input into separate lines
- puts each line into a box
- result is
{"3 4" "4 3" "2 5" "1 3" "3 9" "3 3"}
- given a single row of that array (eg
⊢
first) I can split it by spaces and parse it, use⋕ ⊜□¬ ⊸⌕ " " °□
to turn it from{"3 4"}
into[3 4]
- ≡ rows does the parsing on every line of the input
- result is
╭─
╷ 3 4
4 3
2 5
1 3
3 9
3 3
╯
°⊟⍉
uncouple transpose this gives the input in the form I wanted to start with, hurray!
[4 3 5 3 9 3]
[3 4 2 1 3 3]
Using real input 📩°⊟⍉≡🗒️📋💾
gave the correct solution.
⊜(⊜⋕⊸≠@ )⊸≠@\n
(from Kaikalii on the uiua discord)