51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use std::collections::HashMap;
|
|
|
|
pub fn task_one(input: &str) -> String {
|
|
let line = input.lines().next().unwrap();
|
|
let chars: Vec<char> = line.chars().collect();
|
|
|
|
let mut index = 4;
|
|
let mut iterator = chars.windows(4);
|
|
|
|
while let Some([first, second, third, fourth]) = iterator.next() {
|
|
if first != second && first != third && first != fourth && second != third && second != fourth && third != fourth {
|
|
break;
|
|
}
|
|
|
|
index += 1;
|
|
}
|
|
|
|
index.to_string()
|
|
}
|
|
|
|
pub fn task_two(input: &str) -> String {
|
|
|
|
let line = input.lines().next().unwrap();
|
|
let chars: Vec<char> = line.chars().collect();
|
|
|
|
let mut index = 14;
|
|
let mut iterator = chars.windows(14);
|
|
|
|
while let Some(slice) = iterator.next() {
|
|
let mut dict = HashMap::new();
|
|
let mut next = false;
|
|
|
|
for c in slice {
|
|
if dict.contains_key(&c) {
|
|
next = true;
|
|
break;
|
|
} else {
|
|
dict.insert(c, "");
|
|
}
|
|
}
|
|
|
|
if !next {
|
|
break;
|
|
}
|
|
|
|
index += 1;
|
|
}
|
|
|
|
index.to_string()
|
|
}
|