2022 day6/rust: relax type bounds
This commit is contained in:
parent
236b80b45c
commit
59c1d54801
1 changed files with 3 additions and 5 deletions
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue