aboutsummaryrefslogtreecommitdiff
path: root/2024/01/puzzle-1.awk
blob: 851ecce02638d87dfc36bdfeac6db8af3b11737a (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[NR] = $1
	ys[NR] = $2
}

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