diff --git a/src/days/d06.rs b/src/days/d06.rs index ff3be25..bce9227 100644 --- a/src/days/d06.rs +++ b/src/days/d06.rs @@ -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) -> i32 { @@ -34,3 +36,13 @@ fn find_marker(l: usize, chars: &Vec) -> i32 { -1 } + +fn _find_marker_v2(l: usize, chars: &Vec) -> usize { + chars.iter() + .filter(|c| **c != '\n') + .collect::>() + .windows(l) + .position(|window| window.iter().collect::>().len() == l) + .map(|pos| pos+l) + .unwrap() +} \ No newline at end of file