From 82ede0ec381dfc781ad003edf6c16b99e93ef1cb Mon Sep 17 00:00:00 2001 From: Jonathan Flueren <11487762+JonOfUs@users.noreply.github.com> Date: Tue, 6 Dec 2022 22:02:11 +0100 Subject: [PATCH] Day 6 - add 2nd solving strategy --- src/days/d06.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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