advent-of-code/2019/04/src/main.rs

19 lines
543 B
Rust
Raw Normal View History

2019-12-04 20:47:17 +01:00
#![feature(is_sorted)]
use itertools::Itertools;
pub fn main() {
2019-12-04 22:18:55 +01:00
let valid_part1 = (172_930..683_082)
2019-12-04 20:47:17 +01:00
.map(|n| n.to_string().chars().collect::<Vec<_>>())
.filter(|n| n.is_sorted())
.filter(|v| v.clone().iter().dedup().count() != v.len());
println!("Part 1: {}", valid_part1.clone().count());
2019-12-04 21:46:37 +01:00
2019-12-04 22:18:55 +01:00
let part2 = valid_part1.filter(|vec| {
vec.iter()
.group_by(move |n| *n)
.into_iter()
2019-12-05 06:59:44 +01:00
.any(|(_, v)| v.count() == 2)
2019-12-04 22:18:55 +01:00
});
println!("Part 2: {}", part2.count());
2019-12-04 20:47:17 +01:00
}