40 lines
849 B
Plaintext
40 lines
849 B
Plaintext
func part1[l1: Array, l2: Array] : void
|
|
out := 0
|
|
|
|
for i in 0..l1->size
|
|
out += math.abs(array.nth(l1, i) - array.nth(l2, i))
|
|
|
|
io.println_i64(out)
|
|
|
|
func part2[l1: Array, l2: Array] : void
|
|
out := 0
|
|
|
|
for i in 0..l1->size
|
|
out += array.nth(l1, i) * alg.count(l2, array.nth(l1, i))
|
|
|
|
io.println_i64(out)
|
|
|
|
func main[] : i64
|
|
~input, ok := io.read_text_file("input.txt")
|
|
if !ok
|
|
panic("failed to open input.txt")
|
|
|
|
lines := str.split(input, "\n")
|
|
|
|
l1 := []
|
|
l2 := []
|
|
|
|
for i in 0..lines->size
|
|
line : str = array.nth(lines, i)
|
|
|
|
parts := str.split(line, " ")
|
|
|
|
array.push(l1, str.parse_i64(array.nth(parts, 0)))
|
|
array.push(l2, str.parse_i64(array.nth(parts, 1)))
|
|
|
|
alg.quicksort(l1)
|
|
alg.quicksort(l2)
|
|
|
|
part1(l1, l2)
|
|
part2(l1, l2)
|