Files
aoc-2022/src/day06/mod.rs
2022-12-06 05:27:53 +00:00

28 lines
568 B
Rust

use crate::read;
use std::collections::HashSet;
fn check(chars: &[char], len: usize) -> usize {
chars
.windows(len)
.enumerate()
.find(|(_idx, w)| w.iter().collect::<HashSet<_>>().len() == len)
.unwrap()
.0
+ len
}
pub fn run() {
let input = read("06");
let chars = input.chars().collect::<Vec<_>>();
#[cfg(feature = "part1")]
{
println!("Day 6, Part 01: {}", check(&chars, 4));
}
#[cfg(feature = "part2")]
{
println!("Day 6, Part 02: {}", check(&chars, 14));
}
}