Day 9 part 1
This commit is contained in:
parent
6f3f655eb7
commit
cc2e040332
1 changed files with 66 additions and 0 deletions
66
src/bin/day9.rs
Normal file
66
src/bin/day9.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use aoc_2025::{load, print_res};
|
||||
use bstr::BString;
|
||||
|
||||
pub struct Point2 {
|
||||
x: u64,
|
||||
y: u64,
|
||||
}
|
||||
|
||||
type Parsed = Vec<Point2>;
|
||||
|
||||
#[inline(never)]
|
||||
pub fn parsing(input: &BString) -> color_eyre::Result<Parsed> {
|
||||
str::from_utf8(input)?
|
||||
.lines()
|
||||
.map(|v| {
|
||||
let Some((x, y)) = v.split_once(',') else {
|
||||
color_eyre::eyre::bail!("Malformed point: {v}");
|
||||
};
|
||||
Ok(Point2 {
|
||||
x: x.parse()?,
|
||||
y: y.parse()?,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn part1(input: Parsed) {
|
||||
let max_area = input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(ia, a)| input.iter().skip(ia + 1).map(move |b| (a, b)))
|
||||
.map(|(a, b)| (a.x.abs_diff(b.x) + 1) * (a.y.abs_diff(b.y) + 1))
|
||||
.max()
|
||||
.unwrap();
|
||||
|
||||
print_res!("Max area: {max_area}");
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn part2(input: Parsed) {
|
||||
todo!("todo part2")
|
||||
}
|
||||
|
||||
pub fn main() -> color_eyre::Result<()> {
|
||||
let context = load()?;
|
||||
|
||||
let start = Instant::now();
|
||||
let parsed = parsing(&context.input)?;
|
||||
let elapsed = humantime::format_duration(start.elapsed());
|
||||
|
||||
let start = Instant::now();
|
||||
if context.part == 1 {
|
||||
part1(parsed);
|
||||
} else {
|
||||
part2(parsed);
|
||||
}
|
||||
let elapsed_part = humantime::format_duration(start.elapsed());
|
||||
|
||||
println!(" Parsing: {elapsed}");
|
||||
println!(" Solving: {elapsed_part}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue