Day 6
This commit is contained in:
parent
a546d63914
commit
d35e9844e0
32
src/day06.rs
Normal file
32
src/day06.rs
Normal 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!();
|
||||
}
|
@ -5,5 +5,6 @@ mod day02;
|
||||
mod day03;
|
||||
mod day04;
|
||||
mod day05;
|
||||
mod day06;
|
||||
|
||||
aoc_lib! { year = 2022 }
|
||||
|
Loading…
Reference in New Issue
Block a user