39 lines
797 B
Plaintext
39 lines
797 B
Plaintext
func part1[l1: Array, l2: Array] : void
|
|
out := 0
|
|
|
|
for i in 0..l1->size
|
|
out += (l1->nth(i) as i64 - l2->nth(i) as i64)->abs()
|
|
|
|
io.println_i64(out)
|
|
|
|
func part2[l1: Array, l2: Array] : void
|
|
out := 0
|
|
|
|
for i in 0..l1->size
|
|
out += l1->nth(i) * l2->count(l1->nth(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 := input->split("\n")
|
|
|
|
l1 := []
|
|
l2 := []
|
|
|
|
for i in 0..lines->size
|
|
line : str = lines->nth(i)
|
|
parts := line->split(" ")
|
|
|
|
l1->push((parts->nth(0) as str)->parse_i64())
|
|
l2->push((parts->nth(1) as str)->parse_i64())
|
|
|
|
l1->quicksort()
|
|
l2->quicksort()
|
|
|
|
part1(l1, l2)
|
|
part2(l1, l2)
|