2022 rust day 6

This commit is contained in:
Maciej Jur 2022-12-06 13:54:39 +01:00
parent 9148cdbdd1
commit a81d2e2d71

View file

@ -22,13 +22,11 @@ fn solve2(data: &Vec<char>) -> usize {
fn marker_for(data: &Vec<char>, window_len: usize) -> usize {
data.windows(window_len)
.enumerate()
.filter_map(|(idx, window)| {
let unique = window.iter().copied().collect::<HashSet<char>>().len() == window_len;
match unique {
true => Some(idx + window_len),
false => None
}
})
.filter_map(|(idx, window)| window.iter()
.collect::<HashSet<_>>()
.len().eq(&window_len)
.then_some(idx + window_len)
)
.next().unwrap()
}