summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2022/day03.awk17
1 files changed, 17 insertions, 0 deletions
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;
+}