37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
|
use std::fs::File;
|
||
|
use std::io::{self, BufRead};
|
||
|
use std::path::Path;
|
||
|
|
||
|
fn main() {
|
||
|
let file_path = String::from("/home/wafoo/advent_of_code_2022/aoc_06a/input2");
|
||
|
let mut index = 4;
|
||
|
|
||
|
println!("In file {}", file_path);
|
||
|
|
||
|
if let Ok(lines) = read_lines(file_path) {
|
||
|
// Consumes the iterator, returns an (Optional) String
|
||
|
for line in lines {
|
||
|
if let Ok(ip) = line {
|
||
|
let mut slice = &ip[(index - 4)..index];
|
||
|
while !(slice[0..1] != slice[1..2]
|
||
|
&& slice[1..2] != slice[2..3]
|
||
|
&& slice[0..1] != slice[2..3]
|
||
|
&& slice[0..1] != slice[3..4]
|
||
|
&& slice[1..2] != slice[3..4]
|
||
|
&& slice[2..3] != slice[3..4])
|
||
|
{
|
||
|
index += 1;
|
||
|
slice = &ip[(index - 4)..index];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
println!("{}", index);
|
||
|
}
|
||
|
|
||
|
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
||
|
where P: AsRef<Path>, {
|
||
|
let file = File::open(filename)?;
|
||
|
Ok(io::BufReader::new(file).lines())
|
||
|
}
|