This commit is contained in:
dolphinau 2025-12-09 11:42:54 +01:00
parent c350dea4a3
commit 0917bef99c
3 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,55 @@
use std::collections::BTreeSet;
use crate::days::Solution;
pub struct Database {
ranges: Vec<(usize, usize)>,
ingredients: Vec<usize>,
}
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::<usize>());
(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
}
}

View file

@ -2,6 +2,7 @@ pub mod day01;
pub mod day02; pub mod day02;
pub mod day03; pub mod day03;
pub mod day04; pub mod day04;
pub mod day05;
pub trait Solution { pub trait Solution {
type Input; type Input;

View file

@ -37,6 +37,7 @@ fn main() {
2 => run(cli.day, days::day02::Day02), 2 => run(cli.day, days::day02::Day02),
3 => run(cli.day, days::day03::Day03), 3 => run(cli.day, days::day03::Day03),
4 => run(cli.day, days::day04::Day04), 4 => run(cli.day, days::day04::Day04),
5 => run(cli.day, days::day05::Day05),
_ => { _ => {
eprintln!("Day {:02} is not implemented yet!", cli.day); eprintln!("Day {:02} is not implemented yet!", cli.day);
process::exit(1); process::exit(1);