diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-12-01 17:21:32 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-12-01 17:21:32 +0100 |
commit | 9ad233e4d967f7c134a1d6c50965bcdb722432ab (patch) | |
tree | 5e1807631bc41d2be760ceda8b8c0f23520003b5 /2024/01/puzzle-1.awk | |
parent | fdba09c1c6c67c9081cf470cd6b3c4e8b7670cf6 (diff) |
Add solutions for 2024 day 1
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 |