Day 6 - add 2nd solving strategy
This commit is contained in:
parent
f5a7defd00
commit
82ede0ec38
1 changed files with 12 additions and 0 deletions
|
@ -18,6 +18,8 @@ pub fn solve() {
|
|||
println!("Result 2: {}", res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Finds 1st occurence of l unique characters in chars and returns
|
||||
// the index of the last of them or -1
|
||||
fn find_marker(l: usize, chars: &Vec<char>) -> i32 {
|
||||
|
@ -34,3 +36,13 @@ fn find_marker(l: usize, chars: &Vec<char>) -> i32 {
|
|||
|
||||
-1
|
||||
}
|
||||
|
||||
fn _find_marker_v2(l: usize, chars: &Vec<char>) -> usize {
|
||||
chars.iter()
|
||||
.filter(|c| **c != '\n')
|
||||
.collect::<Vec<&char>>()
|
||||
.windows(l)
|
||||
.position(|window| window.iter().collect::<HashSet<_>>().len() == l)
|
||||
.map(|pos| pos+l)
|
||||
.unwrap()
|
||||
}
|
Loading…
Reference in a new issue