days 5 + 6
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
use rustc_hash::FxHashSet;
|
||||
const PACKET_WINDOW_SIZE: usize = 4;
|
||||
const MESSAGE_WINDOW_SIZE: usize = 14;
|
||||
|
||||
fn main() {
|
||||
let s = std::fs::read_to_string("/dev/stdin").unwrap();
|
||||
println!("P1: {}, P2: {}", find_index(&s, PACKET_WINDOW_SIZE), find_index(&s, MESSAGE_WINDOW_SIZE));
|
||||
}
|
||||
|
||||
fn find_index(s: &str, window_size: usize) -> usize {
|
||||
for (count, window) in s.chars().collect::<Vec<char>>().windows(window_size).enumerate(){
|
||||
if FxHashSet::from_iter(window).len() == window_size {
|
||||
return count + window_size;
|
||||
}
|
||||
}
|
||||
0
|
||||
}
|
||||
Reference in New Issue
Block a user