aoc22/day06/src/main1.rs

27 lines
599 B
Rust
Raw Normal View History

2024-03-10 03:02:11 -05:00
use std::env;
use std::fs::File;
use std::io::{BufReader, Read};
fn main() {
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
let reader = BufReader::new(file);
let (mut x1, mut x2, mut x3) = (0, 0, 0);
let mut i = 0;
for byte in reader.bytes() {
i += 1;
let c = byte.unwrap();
if c != x1 && c != x2 && c != x3
&& x1 != x2 && x1 != x3 && x2 != x3
&& x1 != 0 {
println!("{}", i);
break;
} else {
x1 = x2;
x2 = x3;
x3 = c;
}
}
}