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(-) 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 value='somasis/tokipona'>somasis/tokipona IRC client
summary refs log tree commit diff
path: root/Makefile (unfollow)
Commit message (Expand)Author
2020-02-10Always increase unreadLinesJune McEnroe
2020-02-10Move scroll marker on resizeJune McEnroe
2020-02-10Update line count for words longer than linesJune McEnroe
2020-02-10Simplify mark, heat, unread trackingJune McEnroe
2020-02-10Update prompt when own nick changesJune McEnroe
2020-02-10Match URLs surrounded by parenthesesJune McEnroe
2020-02-10Fix M-a so it properly cycles back to where it startedJune McEnroe
2020-02-09Add M-lJune McEnroe
2020-02-09Add /whoisJune McEnroe
2020-02-09Add /msgJune McEnroe