From 9ad233e4d967f7c134a1d6c50965bcdb722432ab Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 1 Dec 2024 17:21:32 +0100 Subject: Add solutions for 2024 day 1 --- 2024/01/puzzle-1.awk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 2024/01/puzzle-1.awk (limited to '2024/01/puzzle-1.awk') 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 -- cgit v1.2.3