From e7c9108b95e39d7ea5a29ae06d619c4727f11027 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 29 Oct 2021 23:02:39 +0200 Subject: Initial commit --- 2020/04/puzzle-1.awk | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 2020/04/puzzle-1.awk (limited to '2020/04/puzzle-1.awk') 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 } -- cgit v1.2.3