aboutsummaryrefslogtreecommitdiff
path: root/2022/04/puzzles.awk
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-04 16:06:46 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-04 16:06:46 +0100
commit30fb572a31f7a71b7111a9e2645423ee49a09baa (patch)
tree2d4220a9711f1958f7ff755934c49dd396f35c78 /2022/04/puzzles.awk
parentccc1ac4b643dfa692fe0c37f57e9493494245ecb (diff)
Add 2022 day 4 solutions
Diffstat (limited to '2022/04/puzzles.awk')
-rw-r--r--2022/04/puzzles.awk10
1 files changed, 10 insertions, 0 deletions
diff --git a/2022/04/puzzles.awk b/2022/04/puzzles.awk
new file mode 100644
index 0000000..8ba715d
--- /dev/null
+++ b/2022/04/puzzles.awk
@@ -0,0 +1,10 @@
+#!/usr/bin/awk -f
+
+BEGIN { FS = "[,-]" }
+# START PART 1
+($1 <= $3 && $2 >= $4) || ($1 >= $3 && $2 <= $4) { c++ }
+# END PART 1 START PART 2
+($3 >= $1 && $3 <= $2) || ($4 >= $1 && $4 <= $2) ||
+ ($1 >= $3 && $1 <= $4) || ($2 >= $3 && $2 <= $4) { c++ }
+# END PART 2
+END { print c }