day04 task 1

This commit is contained in:
Johannes
2019-12-04 20:55:19 +01:00
parent c6bb71b1db
commit f6d88cf5cd
3 changed files with 19 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
mod tasks; mod tasks;
fn main() { fn main() {
tasks::day03::run(); tasks::day04::run();
} }

17
src/tasks/day04.rs Normal file
View 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);
}

View File

@@ -1,2 +1,3 @@
pub mod day01; pub mod day01;
pub mod day03; pub mod day03;
pub mod day04;