Skip to content
Snippets Groups Projects
Commit fe56aee0 authored by Falk Rehse's avatar Falk Rehse
Browse files

Day 6-2

parent e062b49d
No related branches found
No related tags found
No related merge requests found
const SEQUENCE_LENGTH: usize = 14;
pub fn solve_from_str(input: &str) -> usize {
let chars: Vec<char> = input.chars().collect();
for i in 0..chars.len() - 4 {
if !check_for_duplicate(&chars, i, SEQUENCE_LENGTH) {
return i + SEQUENCE_LENGTH;
}
}
panic!("Expected to find section without duplicate!");
}
fn check_for_duplicate(chars: &Vec<char>, index: usize, amount: usize) -> bool {
let mut range = Vec::with_capacity(amount);
for i in index..index + amount {
range.push(chars[i]);
}
range.sort_unstable();
range.dedup();
range.len() != amount
}
...@@ -9,13 +9,14 @@ mod day_4_2; ...@@ -9,13 +9,14 @@ mod day_4_2;
mod day_5_1; mod day_5_1;
mod day_5_2; mod day_5_2;
mod day_6_1; mod day_6_1;
mod day_6_2;
use std::fs; use std::fs;
fn main() { fn main() {
let input = fs::read_to_string("input").expect("Could not read input!"); let input = fs::read_to_string("input").expect("Could not read input!");
let solution = day_6_1::solve_from_str(input.as_str()); let solution = day_6_2::solve_from_str(input.as_str());
println!("Solution: {}", solution); println!("Solution: {}", solution);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment