aboutsummaryrefslogtreecommitdiff
path: root/2024/01/puzzle-1.awk
blob: ff361aa3a166ea8bcfb8280803e6bf88f8be98c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/awk -f

function abs(n) {
	return n < 0 ? -n : n
}

{
	xs[++i] = $1
	ys[i]   = $2
}

END {
	asort(xs)
	asort(ys)
	for (i in xs)
		d += abs(xs[i] - ys[i])
	print d
}