aboutsummaryrefslogtreecommitdiff
path: root/2025
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2025-12-09 21:49:05 +0100
committerThomas Schmucker <ts@its1.de>2025-12-09 21:49:05 +0100
commit3483f7d1806e63eb6ee7723702a8065106f651f6 (patch)
treeef00581a17e6112df642bc04889e45483d4cef1a /2025
parentd88a2248710f3b9a9a2a6e16707f20b5662d72ab (diff)
downloadadvent-of-code-3483f7d1806e63eb6ee7723702a8065106f651f6.tar.gz
advent-of-code-3483f7d1806e63eb6ee7723702a8065106f651f6.tar.bz2
advent-of-code-3483f7d1806e63eb6ee7723702a8065106f651f6.zip
aoc 2025, day 9, part 2
Diffstat (limited to '2025')
-rw-r--r--2025/src/day09.cpp29
1 files changed, 6 insertions, 23 deletions
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<long, long, long, long>& rect)
64 const auto [x1, y1] = start; 64 const auto [x1, y1] = start;
65 const auto [x2, y2] = end; 65 const auto [x2, y2] = end;
66 66
67 const auto [left, top, right, bottom] = rect; 67 const auto min_x = min(x1, x2);
68 68 const auto max_x = max(x1, x2);
69 if ( x1 == x2 ) { 69 const auto min_y = min(y1, y2);
70 if ( x1 <= left || x1 >= right ) { 70 const auto max_y = max(y1, y2);
71 return false;
72 }
73
74 const auto min_y = min(y1, y2);
75 const auto max_y = max(y1, y2);
76
77 return max_y > top && min_y < bottom;
78 }
79 71
80 if ( y1 == y2 ) { 72 const auto [left, top, right, bottom] = rect;
81 if ( y1 <= top || y1 >= bottom ) {
82 return false;
83 }
84
85 auto min_x = min(x1, x2);
86 auto max_x = max(x1, x2);
87
88 return max_x > left && min_x < right;
89 }
90 73
91 return false; 74 return max_x > left && min_x < right && max_y > top && min_y < bottom;
92} 75}
93 76
94bool 77bool