Add README and solution for day4
This commit is contained in:
@@ -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"
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user