29 lines
880 B
Rust
29 lines
880 B
Rust
---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());
|
|
}
|