diff --git a/2022-aoc/src/d6.rs b/2022-aoc/src/d6.rs new file mode 100644 index 0000000..e5cd635 --- /dev/null +++ b/2022-aoc/src/d6.rs @@ -0,0 +1,23 @@ +use aoc_runner_derive::{aoc as aoc_run, aoc_generator}; +use std::collections::HashSet; + +type Beep = HashSet; + +#[aoc_generator(day6)] +fn parse_input_day1(input: &str) -> String { + input.to_string() +} +#[aoc_run(day6, part1)] +fn part1(input: &str) -> usize { + let input = input.trim(); + let mut out = 4; + for (i, c) in input.as_bytes().windows(4).enumerate() { + let window = Beep::from_iter(c.iter().map(|c| *c as char)); + out = i + 4; + dbg!(i, std::str::from_utf8(c).unwrap(), &window); + if window.len() == 4 { + break; + } + } + out +} diff --git a/2022-aoc/src/lib.rs b/2022-aoc/src/lib.rs index 0457abf..ef0d57a 100644 --- a/2022-aoc/src/lib.rs +++ b/2022-aoc/src/lib.rs @@ -5,5 +5,6 @@ mod d2; mod d3; mod d4; mod d5; +mod d6; aoc_lib! { year = 2022 }