aoc2024/d01/run.awk

17 lines
220 B
Awk
Raw Normal View History

2024-12-01 14:27:43 +00:00
{
l[NR] = $1
r[NR] = $2
C[$2]++
}
END {
asort(l)
asort(r)
for (i = 1; i <= NR; i++) {
d = l[i] - r[i]
D1 += (d < 0) ? -d : d
D2 += l[i] * C[l[i]]
}
print D1, D2
}