From 61c244e84dea782f17c2e7377c405e0ac4198cfc Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 4 Dec 2022 18:00:16 -0500 Subject: Solve day 3 part 1 --- 2022/day03.awk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 2022/day03.awk diff --git a/2022/day03.awk b/2022/day03.awk new file mode 100644 index 0000000..6a4a153 --- /dev/null +++ b/2022/day03.awk @@ -0,0 +1,17 @@ +function common(a, b) { + split(a, as, ""); + for (i in as) { + if (index(b, as[i])) return as[i]; + } +} +function priority(x) { + return index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", x); +} +{ + a = substr($1, 1, length($1)/2); + b = substr($1, length($1)/2 + 1); + sum += priority(common(a, b)); +} +END { + print sum; +} -- cgit 1.4.1