2022 day6/rust: relax type bounds

This commit is contained in:
Xiretza 2022-12-06 17:32:44 +01:00
parent 236b80b45c
commit 59c1d54801

View file

@ -2,17 +2,15 @@
use std::io::{stdin, Read};
fn all_distinct<T: Ord>(slice: &[T]) -> bool {
fn all_distinct<T: PartialEq>(slice: &[T]) -> bool {
slice
.iter()
.enumerate()
.all(|(i, x)| slice[i + 1..].iter().all(|y| y != x))
}
fn end_of_first_distinct_run<T: Ord>(data: &[T], len: usize) -> Option<usize> {
data.windows(len)
.position(|cs| all_distinct(cs))
.map(|i| i + len)
fn end_of_first_distinct_run<T: PartialEq>(data: &[T], len: usize) -> Option<usize> {
data.windows(len).position(all_distinct).map(|i| i + len)
}
fn main() {