From 3483f7d1806e63eb6ee7723702a8065106f651f6 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Tue, 9 Dec 2025 21:49:05 +0100 Subject: aoc 2025, day 9, part 2 --- 2025/src/day09.cpp | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to '2025') diff --git a/2025/src/day09.cpp b/2025/src/day09.cpp index 796bf07..7eaf842 100644 --- a/2025/src/day09.cpp +++ b/2025/src/day09.cpp @@ -64,31 +64,14 @@ intersects(const Segment& line, const tuple& rect) const auto [x1, y1] = start; const auto [x2, y2] = end; - const auto [left, top, right, bottom] = rect; - - if ( x1 == x2 ) { - if ( x1 <= left || x1 >= right ) { - return false; - } - - const auto min_y = min(y1, y2); - const auto max_y = max(y1, y2); - - return max_y > top && min_y < bottom; - } + const auto min_x = min(x1, x2); + const auto max_x = max(x1, x2); + const auto min_y = min(y1, y2); + const auto max_y = max(y1, y2); - if ( y1 == y2 ) { - if ( y1 <= top || y1 >= bottom ) { - return false; - } - - auto min_x = min(x1, x2); - auto max_x = max(x1, x2); - - return max_x > left && min_x < right; - } + const auto [left, top, right, bottom] = rect; - return false; + return max_x > left && min_x < right && max_y > top && min_y < bottom; } bool -- cgit v1.3