2022 rust day 6
This commit is contained in:
parent
9148cdbdd1
commit
a81d2e2d71
|
@ -22,13 +22,11 @@ fn solve2(data: &Vec<char>) -> usize {
|
||||||
fn marker_for(data: &Vec<char>, window_len: usize) -> usize {
|
fn marker_for(data: &Vec<char>, window_len: usize) -> usize {
|
||||||
data.windows(window_len)
|
data.windows(window_len)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(idx, window)| {
|
.filter_map(|(idx, window)| window.iter()
|
||||||
let unique = window.iter().copied().collect::<HashSet<char>>().len() == window_len;
|
.collect::<HashSet<_>>()
|
||||||
match unique {
|
.len().eq(&window_len)
|
||||||
true => Some(idx + window_len),
|
.then_some(idx + window_len)
|
||||||
false => None
|
)
|
||||||
}
|
|
||||||
})
|
|
||||||
.next().unwrap()
|
.next().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue