aboutsummaryrefslogtreecommitdiff
path: root/2020/04/puzzle-1.awk
diff options
context:
space:
mode:
Diffstat (limited to '2020/04/puzzle-1.awk')
-rwxr-xr-x2020/04/puzzle-1.awk30
1 files changed, 30 insertions, 0 deletions
diff --git a/2020/04/puzzle-1.awk b/2020/04/puzzle-1.awk
new file mode 100755
index 0000000..4c0c474
--- /dev/null
+++ b/2020/04/puzzle-1.awk
@@ -0,0 +1,30 @@
+#!/usr/bin/env -S awk -f
+
+length == 0 {
+ valid = 1
+ for (i in fields) {
+ if (fields[i] == "")
+ valid = 0
+ }
+
+ if (valid)
+ count++
+
+ fields["byr"] = ""
+ fields["iyr"] = ""
+ fields["eyr"] = ""
+ fields["hgt"] = ""
+ fields["hcl"] = ""
+ fields["ecl"] = ""
+ fields["pid"] = ""
+}
+
+{
+ for (i = 1; i <= NF; i++) {
+ split($i, data, ":")
+ fields[data[1]] = data[2]
+ }
+}
+
+# Why do I need to subtract one? This code is so old I can't remember
+END { print count - 1 }