summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-04 18:39:38 -0500
committerJune McEnroe <june@causal.agency>2022-12-04 18:39:38 -0500
commit195e1ccc7c152a528f3df677fb3895aa9de9d1c6 (patch)
tree92ce6faddd5e6d4417ac29db08d2d3dc6586f48f
parentSolve day 4 part 1 (diff)
downloadaoc-195e1ccc7c152a528f3df677fb3895aa9de9d1c6.tar.gz
aoc-195e1ccc7c152a528f3df677fb3895aa9de9d1c6.zip
Solve day 4 part 2
-rw-r--r--2022/day04.awk9
1 files changed, 7 insertions, 2 deletions
diff --git a/2022/day04.awk b/2022/day04.awk
index 78ff511..00b11f2 100644
--- a/2022/day04.awk
+++ b/2022/day04.awk
@@ -4,9 +4,14 @@ BEGIN {
 function contains(a, b, x, y) {
 	return x >= a && y <= b;
 }
+function overlaps(a, b, x, y) {
+	return (x >= a && x <= b) || (y >= a && y <= b);
+}
 {
-	if (contains($1, $2, $3, $4) || contains($3, $4, $1, $2)) pairs++;
+	if (contains($1, $2, $3, $4) || contains($3, $4, $1, $2)) pairs1++;
+	if (overlaps($1, $2, $4, $4) || overlaps($3, $4, $1, $2)) pairs2++;
 }
 END {
-	print pairs;
+	print pairs1;
+	print pairs2;
 }