Implement 2025 - Day 9 - Part 1
This commit is contained in:
28
2025/09.rs
Normal file
28
2025/09.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
---cargo
|
||||
---
|
||||
|
||||
static CONTENT: &'static str = include_str!("./inputs/09_1.txt");
|
||||
|
||||
fn main() {
|
||||
let points: Vec<(usize, usize)> = CONTENT.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
|
||||
let (first, second) = l.split_once(',').unwrap();
|
||||
|
||||
let first = first.parse::<usize>().unwrap();
|
||||
let second = second.parse::<usize>().unwrap();
|
||||
|
||||
(first, second)
|
||||
}).collect();
|
||||
println!("Points:\n{:?}", points);
|
||||
|
||||
let mut rects: Vec<((usize, usize), (usize, usize), usize)> = points.iter()
|
||||
.flat_map(|p| core::iter::repeat(*p).zip(points.iter().copied()))
|
||||
.filter(|(f, s)| f != s)
|
||||
.map(|(f, s)| (f, s, (f.0.abs_diff(s.0)+1) * (f.1.abs_diff(s.1)+1)))
|
||||
.collect();
|
||||
|
||||
rects.sort_by_key(|(_, _, a)| *a);
|
||||
|
||||
// println!("Rectangle: {:?}", rects);
|
||||
|
||||
println!("Largest: {:?}", rects.last().unwrap());
|
||||
}
|
||||
Reference in New Issue
Block a user