Even faster

This commit is contained in:
Dreaded_X 2022-12-06 22:08:56 +01:00
parent 386f764fbd
commit 3ef5039528
Signed by: Dreaded_X
GPG Key ID: 76BDEC4E165D8AD9

View File

@ -76,25 +76,24 @@ mod tests {
}
// -- Helpers --
fn is_start_marker((index, window): (usize, &[u8])) -> Option<usize> {
fn is_start_marker(window: &[u8]) -> bool {
for i in 0..window.len() {
for j in i+1..window.len() {
if window[i] == window[j] {
return None;
return false;
}
}
}
return Some(index + window.len());
return true;
}
fn solution(input: &str, length: usize) -> usize {
input
.as_bytes()
.windows(length)
.enumerate()
.find_map(is_start_marker)
.expect("Invalid input")
.position(is_start_marker)
.expect("Invalid input") + length
}
// -- Solution --