38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
use std::fs::File;
|
|
use std::io::{self, BufRead};
|
|
use std::path::Path;
|
|
use std::collections::HashMap;
|
|
|
|
fn main() {
|
|
let file_path = String::from("../aoc_06a/input");
|
|
let mut index = 14;
|
|
|
|
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 len = 0;
|
|
while len != 14 {
|
|
let mut hashmap = HashMap::new();
|
|
let slice = &ip[(index - 14)..index];
|
|
for c in slice.chars() {
|
|
hashmap.insert(c, 0);
|
|
}
|
|
len = hashmap.len();
|
|
index += 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
println!("{}", index - 1);
|
|
}
|
|
|
|
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())
|
|
}
|