aboutsummaryrefslogtreecommitdiff
path: root/2022/04/puzzles.awk
diff options
context:
space:
mode:
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 }