advent-of-code/2022/day6/rust/src/main.rs

30 lines
588 B
Rust
Raw Normal View History

2022-12-06 06:12:56 +01:00
#![warn(clippy::pedantic)]
use std::{
collections::HashSet,
io::{stdin, Read},
};
use aoc::*;
fn main() {
let mut data = String::new();
stdin().read_to_string(&mut data).unwrap();
let i = data
.as_bytes()
.windows(4)
.position(|cs| HashSet::<u8>::from_iter(cs.into_iter().copied()).len() == 4)
.unwrap();
println!("{:?}", i + 4);
let i = data
.as_bytes()
.windows(14)
.position(|cs| HashSet::<u8>::from_iter(cs.into_iter().copied()).len() == 14)
.unwrap();
println!("{:?}", i + 14);
}