This commit is contained in:
Max Nuding 2022-12-04 08:03:11 +00:00
parent e54aad2d33
commit 3bd486af95
4 changed files with 1044 additions and 2 deletions

1000
input/04.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@ pub fn run() {
val(lc.unwrap())
})
.sum();
println!("Day 2, Part 01: {}", lines);
println!("Day 3, Part 01: {}", lines);
}
#[cfg(feature = "part2")]
@ -42,6 +42,6 @@ pub fn run() {
val(common.unwrap())
})
.sum();
println!("Day 2, Part 02: {}", lines);
println!("Day 3, Part 02: {}", lines);
}
}

38
src/day04/mod.rs Normal file
View File

@ -0,0 +1,38 @@
use crate::read;
fn get_ranges(elf: &str) -> std::ops::RangeInclusive<i32> {
let r = elf
.split_once('-')
.map(|e| (e.0.parse().unwrap(), e.1.parse().unwrap()))
.unwrap();
r.0..=r.1
}
pub fn run() {
let input = read("04");
let lines = input
.lines()
.map(|l| {
let pairs = l.split_once(',').unwrap();
(get_ranges(pairs.0), get_ranges(pairs.1))
})
.collect::<Vec<_>>();
#[cfg(feature = "part1")]
{
let count = lines
.iter()
.filter(|(a, b)| a.clone().all(|x| b.contains(&x)) || b.clone().all(|x| a.contains(&x)))
.count();
println!("Day 4, Part 01: {}", count);
}
#[cfg(feature = "part2")]
{
let count = lines
.iter()
.filter(|(a, b)| a.clone().any(|x| b.contains(&x)) || b.clone().any(|x| a.contains(&x)))
.count();
println!("Day 4, Part 02: {}", count);
}
}

View File

@ -4,6 +4,7 @@ use std::time::Instant;
mod day01;
mod day02;
mod day03;
mod day04;
fn main() {
let today = Local::now().day();
@ -17,6 +18,9 @@ fn main() {
if cfg!(feature = "day03") || (cfg!(feature = "today") && today == 3) {
day03::run();
}
if cfg!(feature = "day04") || (cfg!(feature = "today") && today == 4) {
day04::run();
}
println!("Finished, time taken: {:?}", now.elapsed())
}