days 5 + 6

This commit is contained in:
2022-12-06 21:26:50 +00:00
parent 70894fa3a8
commit e56f7c64ea
6 changed files with 132 additions and 0 deletions
+17
View File
@@ -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
}