day5 part 1

This commit is contained in:
2026-01-04 22:34:37 +01:00
parent de566cc98d
commit f723f00016
5 changed files with 1218 additions and 1 deletions

34
src/day5/part1.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::fs;
#[allow(dead_code)]
pub fn solve() {
let file = fs::read_to_string("src/day5/input.txt").expect("You didn't provide input.txt.");
let mut reading_ranges = true;
let mut fresh_products = vec![];
let mut ranges = vec![];
for line in file.lines() {
if line.is_empty() {
reading_ranges = false;
continue;
}
if reading_ranges {
let mut parts = line.split("-");
let start = parts.next().unwrap().parse::<usize>().unwrap();
let end = parts.next().unwrap().parse::<usize>().unwrap();
let range = start..=end;
ranges.push(range);
} else {
let value = line.parse::<usize>().unwrap();
for range in &ranges {
if range.contains(&value) {
fresh_products.push(value);
break;
}
}
}
}
println!("Fresh products: {:?}", fresh_products.len());
}