From 0917bef99cc25b0b60c78f531916827c4d3dc5c1 Mon Sep 17 00:00:00 2001 From: dolphinau Date: Tue, 9 Dec 2025 11:42:54 +0100 Subject: [PATCH] day05 --- AoC_2025/src/days/day05.rs | 55 ++++++++++++++++++++++++++++++++++++++ AoC_2025/src/days/mod.rs | 1 + AoC_2025/src/main.rs | 1 + 3 files changed, 57 insertions(+) create mode 100644 AoC_2025/src/days/day05.rs diff --git a/AoC_2025/src/days/day05.rs b/AoC_2025/src/days/day05.rs new file mode 100644 index 0000000..dbaef96 --- /dev/null +++ b/AoC_2025/src/days/day05.rs @@ -0,0 +1,55 @@ +use std::collections::BTreeSet; + +use crate::days::Solution; + +pub struct Database { + ranges: Vec<(usize, usize)>, + ingredients: Vec, +} + +pub struct Day05; + +impl Solution for Day05 { + type Input = Database; + + fn parse(&self, data: &str) -> Self::Input { + let mut lines = data.split("\n"); + Database { + ranges: lines + .by_ref() + .take_while(|l| !l.is_empty()) + .map(|s| { + let mut ints = s.split("-").map(|x| x.parse::()); + (ints.next().unwrap().unwrap(), ints.next().unwrap().unwrap()) + }) + .collect(), + ingredients: lines + .filter(|l| !l.is_empty()) + .map(|s| s.parse().unwrap()) + .collect(), + } + } + + fn part1( + &self, + Self::Input { + ranges, + ingredients, + }: &Self::Input, + ) -> usize { + ingredients + .iter() + .filter(|i| ranges.iter().any(|(x, y)| (x..=y).contains(i))) + .count() + } + + fn part2( + &self, + Self::Input { + ranges, + ingredients: _, + }: &Self::Input, + ) -> usize { + 0 + } +} diff --git a/AoC_2025/src/days/mod.rs b/AoC_2025/src/days/mod.rs index 0d5fd87..9fe28f7 100644 --- a/AoC_2025/src/days/mod.rs +++ b/AoC_2025/src/days/mod.rs @@ -2,6 +2,7 @@ pub mod day01; pub mod day02; pub mod day03; pub mod day04; +pub mod day05; pub trait Solution { type Input; diff --git a/AoC_2025/src/main.rs b/AoC_2025/src/main.rs index 3c957b5..80139eb 100644 --- a/AoC_2025/src/main.rs +++ b/AoC_2025/src/main.rs @@ -37,6 +37,7 @@ fn main() { 2 => run(cli.day, days::day02::Day02), 3 => run(cli.day, days::day03::Day03), 4 => run(cli.day, days::day04::Day04), + 5 => run(cli.day, days::day05::Day05), _ => { eprintln!("Day {:02} is not implemented yet!", cli.day); process::exit(1);