You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
733 B
Rust
27 lines
733 B
Rust
fn main() {
|
|
let contents = std::fs::read_to_string("data.txt").expect("Failed to read file");
|
|
let contents = contents.trim();
|
|
|
|
// Part 1
|
|
for i in 0..contents.len() - 3 {
|
|
let mut chars = contents[i..i + 4].chars().collect::<Vec<char>>();
|
|
chars.sort();
|
|
chars.dedup();
|
|
if chars.len() == 4 {
|
|
println!("Found marker at index {:?}", i + 4);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Part 2
|
|
for i in 0..contents.len() - 13 {
|
|
let mut chars = contents[i..i + 14].chars().collect::<Vec<char>>();
|
|
chars.sort();
|
|
chars.dedup();
|
|
if chars.len() == 14 {
|
|
println!("Found message at index {:?}", i + 14);
|
|
break;
|
|
}
|
|
}
|
|
}
|