From cf7806ca01b50fec98828a50539007a132a19e0e Mon Sep 17 00:00:00 2001 From: setop Date: Sun, 1 Dec 2024 15:27:43 +0100 Subject: [PATCH] day 1 cannot mawk but it can gawk --- d01/run.awk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 d01/run.awk diff --git a/d01/run.awk b/d01/run.awk new file mode 100644 index 0000000..21ebb4e --- /dev/null +++ b/d01/run.awk @@ -0,0 +1,16 @@ +{ + 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 +}