day05
This commit is contained in:
parent
c350dea4a3
commit
0917bef99c
3 changed files with 57 additions and 0 deletions
55
AoC_2025/src/days/day05.rs
Normal file
55
AoC_2025/src/days/day05.rs
Normal 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
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ pub mod day01;
|
|||
pub mod day02;
|
||||
pub mod day03;
|
||||
pub mod day04;
|
||||
pub mod day05;
|
||||
|
||||
pub trait Solution {
|
||||
type Input;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue