Skip to content

Commit 5e54bf1

Browse files
committed
chore: tidy
1 parent 784eddd commit 5e54bf1

File tree

2 files changed

+12
-85
lines changed

2 files changed

+12
-85
lines changed

aoclp/src/positioning/pt.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,7 @@ pub fn min_max<T>(a: Pt<T>, b: Pt<T>) -> (Pt<T>, Pt<T>)
210210
where
211211
T: Ord + Copy,
212212
{
213-
(
214-
Pt::new(min(a.x, b.x), min(a.y, b.y)),
215-
Pt::new(max(a.x, b.x), max(a.y, b.y)),
216-
)
213+
(Pt::new(min(a.x, b.x), min(a.y, b.y)), Pt::new(max(a.x, b.x), max(a.y, b.y)))
217214
}
218215

219216
/// Given two points representing any two opposite corners of a rectangle in 2D space,

aoclp_solutions/src/y2025/day_09.rs

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashSet;
21
use std::fmt;
32
use std::iter::once;
43

@@ -32,89 +31,20 @@ pub fn part_2() -> i64 {
3231
.all(|line| !walls.iter().any(|w| w.intersects(line)))
3332
};
3433

35-
let area = red_tiles
34+
red_tiles
3635
.iter()
3736
.copied()
3837
.array_combinations()
3938
.filter(|[a, b]| valid_rectangle(*a, *b))
4039
.map(|[a, b]| rectangular_area(a, b))
4140
.max()
42-
.unwrap();
43-
44-
let matching_rects = red_tiles
45-
.iter()
46-
.copied()
47-
.array_combinations()
48-
.map(|[a, b]| (a, b, rectangular_area(a, b)))
49-
.filter(|(_, _, ar)| *ar == area)
50-
.filter(|(a, b, _)| valid_rectangle(*a, *b))
51-
.collect_vec();
52-
53-
println!("The largest rectangle has an area of {area}. Matching rectangles:");
54-
for (a, b, _) in matching_rects {
55-
println!(" {a} - {b}");
56-
}
57-
58-
// let line_pts = |line: GridLine| {
59-
// match line {
60-
// GridLine::Horizontal { y, left_x, right_x } => {
61-
// (left_x..=right_x).map(|x| Pt::new(x, y)).collect_vec()
62-
// },
63-
// GridLine::Vertical { x, top_y, bottom_y } => {
64-
// (top_y..=bottom_y).map(|y| Pt::new(x, y)).collect_vec()
65-
// },
66-
// GridLine::Point(p) => vec![p],
67-
// }
68-
// };
69-
//
70-
// let red_tiles_s: HashSet<_> = red_tiles.iter().copied().collect();
71-
// let path_s: HashSet<_> = red_tiles
72-
// .iter()
73-
// .copied()
74-
// .chain(once(red_tiles[0]))
75-
// .tuple_windows()
76-
// .flat_map(|(a, b)| line_pts(GridLine::from_endpoints(a, b)))
77-
// .collect();
78-
// let walls_s: HashSet<_> = walls
79-
// .iter()
80-
// .flat_map(|w| line_pts(*w))
81-
// .collect();
82-
//
83-
// let max_x = red_tiles.iter().map(|p| p.x).max().unwrap() + 3;
84-
// let max_y = red_tiles.iter().map(|p| p.y).max().unwrap() + 3;
85-
//
86-
// for y in 0..=max_y {
87-
// for x in 0..=max_x {
88-
// let p = Pt::new(x, y);
89-
// if red_tiles_s.contains(&p) {
90-
// print!("#");
91-
// } else if walls_s.contains(&p) {
92-
// print!("!");
93-
// } else if path_s.contains(&p) {
94-
// print!("X");
95-
// } else {
96-
// print!(".");
97-
// }
98-
// }
99-
// println!();
100-
// }
101-
// println!();
102-
103-
area
41+
.unwrap()
10442
}
10543

10644
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
10745
enum GridLine {
108-
Horizontal {
109-
y: i64,
110-
left_x: i64,
111-
right_x: i64,
112-
},
113-
Vertical {
114-
x: i64,
115-
top_y: i64,
116-
bottom_y: i64,
117-
},
46+
Horizontal { y: i64, left_x: i64, right_x: i64 },
47+
Vertical { x: i64, top_y: i64, bottom_y: i64 },
11848
Point(Pt),
11949
}
12050

@@ -135,7 +65,7 @@ impl GridLine {
13565
Self::Horizontal { y, left_x: left_x - len, right_x }
13666
},
13767
(Self::Horizontal { y, left_x, right_x }, Direction4::Right) => {
138-
Self::Horizontal { y, left_x, right_x: right_x + len}
68+
Self::Horizontal { y, left_x, right_x: right_x + len }
13969
},
14070
(Self::Vertical { x, top_y, bottom_y }, Direction4::Up) => {
14171
Self::Vertical { x, top_y: top_y - len, bottom_y }
@@ -154,16 +84,16 @@ impl GridLine {
15484

15585
fn intersects(self, rhs: Self) -> bool {
15686
match (self, rhs) {
157-
(Self::Horizontal { y, left_x, right_x }, Self::Vertical { x, top_y, bottom_y }) |
158-
(Self::Vertical { x, top_y, bottom_y }, Self::Horizontal { y, left_x, right_x }) => {
87+
(Self::Horizontal { y, left_x, right_x }, Self::Vertical { x, top_y, bottom_y })
88+
| (Self::Vertical { x, top_y, bottom_y }, Self::Horizontal { y, left_x, right_x }) => {
15989
(top_y..=bottom_y).contains(&y) && (left_x..=right_x).contains(&x)
16090
},
161-
(Self::Horizontal { y, left_x, right_x }, Self::Point(p)) |
162-
(Self::Point(p), Self::Horizontal { y, left_x, right_x }) => {
91+
(Self::Horizontal { y, left_x, right_x }, Self::Point(p))
92+
| (Self::Point(p), Self::Horizontal { y, left_x, right_x }) => {
16393
p.y == y && (left_x..=right_x).contains(&p.x)
16494
},
165-
(Self::Vertical { x, top_y, bottom_y }, Self::Point(p)) |
166-
(Self::Point(p), Self::Vertical { x, top_y, bottom_y }) => {
95+
(Self::Vertical { x, top_y, bottom_y }, Self::Point(p))
96+
| (Self::Point(p), Self::Vertical { x, top_y, bottom_y }) => {
16797
p.x == x && (top_y..=bottom_y).contains(&p.y)
16898
},
16999
_ => false,

0 commit comments

Comments
 (0)