summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-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;
 }