aboutsummaryrefslogtreecommitdiff
path: root/2024/05/puzzle-1.awk
diff options
context:
space:
mode:
Diffstat (limited to '2024/05/puzzle-1.awk')
-rwxr-xr-x2024/05/puzzle-1.awk18
1 files changed, 18 insertions, 0 deletions
diff --git a/2024/05/puzzle-1.awk b/2024/05/puzzle-1.awk
new file mode 100755
index 0000000..bd9ed68
--- /dev/null
+++ b/2024/05/puzzle-1.awk
@@ -0,0 +1,18 @@
+#!/usr/bin/awk -f
+
+BEGIN { FS = "[|,]" }
+
+/\|/ { rules[$1][$2] = 1 }
+/,/ {
+ delete seen
+ for (i = 1; i <= NF; i++) {
+ for (j in seen) {
+ if (j in rules[$i])
+ next
+ }
+ seen[$i] = 1
+ }
+ mid += $(i / 2)
+}
+
+END { print mid } \ No newline at end of file