diff options
Diffstat (limited to '2024/01/puzzle-1.awk')
-rwxr-xr-x | 2024/01/puzzle-1.awk | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/2024/01/puzzle-1.awk b/2024/01/puzzle-1.awk new file mode 100755 index 0000000..ff361aa --- /dev/null +++ b/2024/01/puzzle-1.awk @@ -0,0 +1,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 +}
\ No newline at end of file |