aboutsummaryrefslogtreecommitdiff
path: root/2023/02/puzzle-1.awk
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-02 15:48:50 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-02 15:48:50 +0100
commitc1875f1bee7c07227942a831e466f2c262339439 (patch)
treeb58ccfb0896125294e6c03eef92be0d300b719a8 /2023/02/puzzle-1.awk
parent1dbdc87b6365e5ce852de92a3a2e9ae05c5481a0 (diff)
Add 2023 day 2 solutions
Diffstat (limited to '2023/02/puzzle-1.awk')
-rwxr-xr-x2023/02/puzzle-1.awk31
1 files changed, 31 insertions, 0 deletions
diff --git a/2023/02/puzzle-1.awk b/2023/02/puzzle-1.awk
new file mode 100755
index 0000000..8d68943
--- /dev/null
+++ b/2023/02/puzzle-1.awk
@@ -0,0 +1,31 @@
+#!/usr/bin/awk -f
+
+BEGIN {
+ FS = "[;:] "
+
+ r = 12
+ g = 13
+ b = 14
+}
+
+{
+ for (i = 2; i <= NF; i++) {
+ split($i, xs, /, /)
+ for (j in xs) {
+ split(xs[j], ys, / /)
+ n = ys[1]
+ c = ys[2]
+
+ if (c == "red" && n > r || c == "green" && n > g ||
+ c == "blue" && n > b)
+ next
+ }
+ }
+
+ sub(/Game /, "", $1)
+ sum += $1
+}
+
+END {
+ print sum
+}