diff --git a/src/bin/day9.rs b/src/bin/day9.rs new file mode 100644 index 0000000..990ea6d --- /dev/null +++ b/src/bin/day9.rs @@ -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; + +#[inline(never)] +pub fn parsing(input: &BString) -> color_eyre::Result { + 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(()) +}