Day 04
This commit is contained in:
parent
e54aad2d33
commit
3bd486af95
1000
input/04.txt
Normal file
1000
input/04.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@ pub fn run() {
|
|||||||
val(lc.unwrap())
|
val(lc.unwrap())
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
println!("Day 2, Part 01: {}", lines);
|
println!("Day 3, Part 01: {}", lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "part2")]
|
#[cfg(feature = "part2")]
|
||||||
@ -42,6 +42,6 @@ pub fn run() {
|
|||||||
val(common.unwrap())
|
val(common.unwrap())
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
println!("Day 2, Part 02: {}", lines);
|
println!("Day 3, Part 02: {}", lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
src/day04/mod.rs
Normal file
38
src/day04/mod.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ use std::time::Instant;
|
|||||||
mod day01;
|
mod day01;
|
||||||
mod day02;
|
mod day02;
|
||||||
mod day03;
|
mod day03;
|
||||||
|
mod day04;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let today = Local::now().day();
|
let today = Local::now().day();
|
||||||
@ -17,6 +18,9 @@ fn main() {
|
|||||||
if cfg!(feature = "day03") || (cfg!(feature = "today") && today == 3) {
|
if cfg!(feature = "day03") || (cfg!(feature = "today") && today == 3) {
|
||||||
day03::run();
|
day03::run();
|
||||||
}
|
}
|
||||||
|
if cfg!(feature = "day04") || (cfg!(feature = "today") && today == 4) {
|
||||||
|
day04::run();
|
||||||
|
}
|
||||||
println!("Finished, time taken: {:?}", now.elapsed())
|
println!("Finished, time taken: {:?}", now.elapsed())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user