Skip to content

Commit 131c601

Browse files
committed
feat(09/2025): solve first part
1 parent 8c664d1 commit 131c601

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| [Day 6: Trash Compactor](src/solutions/year2025/day06.rs) | ⭐⭐ | 0.117 | 2.577 |
2020
| [Day 7: Laboratories](src/solutions/year2025/day07.rs) | ⭐⭐ | 6.711 | 5.789 |
2121
| [Day 8: Playground](src/solutions/year2025/day08.rs) | ⭐⭐ | 46.993 | 44.599 |
22+
| [Day 9: Movie Theater](src/solutions/year2025/day09.rs) || 0.387 | - |
2223

2324
# 2024
2425

src/solutions/year2025/day09.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
use crate::solutions::Solution;
2+
use crate::utils::point::Point;
3+
use crate::utils::surface_range::SurfaceRange;
4+
use itertools::Itertools;
25

36
pub struct Day09;
47

58
impl Solution for Day09 {
6-
fn part_one(&self, _input: &str) -> String {
7-
String::from("0")
9+
fn part_one(&self, input: &str) -> String {
10+
self.parse(input)
11+
.into_iter()
12+
.tuple_combinations()
13+
.map(|(a, b)| SurfaceRange::from((a, b)).area())
14+
.max()
15+
.unwrap()
16+
.to_string()
817
}
918

1019
fn part_two(&self, _input: &str) -> String {
1120
String::from("0")
1221
}
1322
}
1423

24+
impl Day09 {
25+
fn parse(&self, input: &str) -> Vec<Point> {
26+
input.lines().map(|line| line.parse().unwrap()).collect()
27+
}
28+
}
29+
1530
#[cfg(test)]
1631
mod tests {
1732
use crate::solutions::year2025::day09::Day09;
1833
use crate::solutions::Solution;
1934

20-
const EXAMPLE: &str = r#""#;
35+
const EXAMPLE: &str = r#"7,1
36+
11,1
37+
11,7
38+
9,7
39+
9,5
40+
2,5
41+
2,3
42+
7,3"#;
2143

2244
#[test]
2345
fn part_one_example_test() {
24-
assert_eq!("0", Day09.part_one(EXAMPLE));
46+
assert_eq!("50", Day09.part_one(EXAMPLE));
2547
}
2648
}

src/utils/range.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ impl Range {
1717
Ok(Self { start, end })
1818
}
1919

20+
pub fn from_unordered(a: isize, b: isize) -> Self {
21+
Self::new(a.min(b), a.max(b)).unwrap()
22+
}
23+
2024
pub fn with_length(start: isize, len: isize) -> Result<Self, String> {
2125
Self::new(start, start + len - 1)
2226
}

src/utils/surface_range.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ impl SurfaceRange {
1616

1717
pub fn from_points(start_x: isize, end_x: isize, start_y: isize, end_y: isize) -> Self {
1818
Self::new(
19-
Range::new(start_x, end_x).unwrap(),
20-
Range::new(start_y, end_y).unwrap(),
19+
Range::from_unordered(start_x, end_x),
20+
Range::from_unordered(start_y, end_y),
2121
)
2222
}
2323

@@ -87,6 +87,12 @@ impl SurfaceRange {
8787
}
8888
}
8989

90+
impl From<(Point, Point)> for SurfaceRange {
91+
fn from((a, b): (Point, Point)) -> Self {
92+
Self::from_points(a.x, b.x, a.y, b.y)
93+
}
94+
}
95+
9096
#[cfg(test)]
9197
mod tests {
9298
use crate::utils::surface_range::SurfaceRange;

0 commit comments

Comments
 (0)