Add README and solution for day4

This commit is contained in:
2019-12-07 12:53:43 +01:00
parent ffbe0f66a1
commit 40e0caa31a
4 changed files with 67 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
[package]
name = "day4"
version = "0.1.0"
authors = ["Tobias Eidelpes <tobias@eidelpes.info>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
itertools = "0.8"
+18
View File
@@ -0,0 +1,18 @@
use itertools::Itertools;
fn main() {
let passwords = (152_086_usize..670_282_usize)
.map(|x| x.to_string().chars().collect::<Vec<char>>())
.filter(|x| x.iter().zip(x.iter().skip(1)).all(|(x,y)| x <= y))
.filter(|x| {
for (_,g) in &x.iter().group_by(|&y| y) {
if g.count() == 2 {
return true;
}
}
false
})
.count();
println!("Solution: {:?}", passwords);
}