From 195e1ccc7c152a528f3df677fb3895aa9de9d1c6 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 4 Dec 2022 18:39:38 -0500 Subject: Solve day 4 part 2 --- 2022/day04.awk | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to '2022') 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; } -- cgit 1.4.1