day04 task 1
This commit is contained in:
17
src/tasks/day04.rs
Normal file
17
src/tasks/day04.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
pub fn run() {
|
||||
let range = 109165..=576723;
|
||||
task1(&range);
|
||||
}
|
||||
|
||||
fn task1(range: &RangeInclusive<i32>) {
|
||||
let count = range
|
||||
.clone()
|
||||
.map(|v| format!("{}", v))
|
||||
.filter(|s| s.chars().zip(s.chars().skip(1)).any(|(a, b)| a == b))
|
||||
.filter(|s| s.chars().zip(s.chars().skip(1)).all(|(a, b)| a <= b))
|
||||
.count();
|
||||
|
||||
println!("Task 1: There are {} valid passwords in the range", count);
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod day01;
|
||||
pub mod day03;
|
||||
pub mod day04;
|
||||
|
||||
Reference in New Issue
Block a user