This commit is contained in:
pjht 2022-12-06 08:23:57 -06:00
parent a546d63914
commit d35e9844e0
2 changed files with 33 additions and 0 deletions

32
src/day06.rs Normal file
View File

@ -0,0 +1,32 @@
use aoc_runner_derive::aoc;
fn check_unique(input: &[char]) -> bool {
for i in 0..input.len() - 1 {
if input[i + 1..input.len()].contains(&input[i]) {
return false;
}
}
true
}
#[aoc(day6, part1)]
fn solve_part1(input: &str) -> usize {
let chars = input.chars().collect::<Vec<_>>();
for (i, window) in chars.windows(4).enumerate() {
if check_unique(window) {
return i + 4;
}
}
panic!();
}
#[aoc(day6, part2)]
fn solve_part2(input: &str) -> usize {
let chars = input.chars().collect::<Vec<_>>();
for (i, window) in chars.windows(14).enumerate() {
if check_unique(window) {
return i + 14;
}
}
panic!();
}

View File

@ -5,5 +5,6 @@ mod day02;
mod day03; mod day03;
mod day04; mod day04;
mod day05; mod day05;
mod day06;
aoc_lib! { year = 2022 } aoc_lib! { year = 2022 }