blob: 0d594793074d2afb1e198b2c9b3484e02e0b22d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
use std::fs;
use std::io::{self, Read};
fn solver(bytes: &Vec<u8>, marker_len: u32) -> u32 {
let mut count = marker_len;
for view in bytes.windows(marker_len as usize) {
let mut acc: u32 = 0;
for elt in view {
acc |= 1 << (elt - 96);
}
if u32::count_ones(acc) >= marker_len {
break;
}
count += 1;
}
count
}
fn main() -> io::Result<()> {
let mut file = fs::File::open("input").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes)?;
println!("All test passed. {}", solver(&bytes, 4));
println!("All test passed. {}", solver(&bytes, 14));
Ok(())
}
|