From 1c7913285c56cc622301357a82dc41df69e99d7b Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 6 Dec 2022 16:30:35 -0800 Subject: [PATCH] done with day6 part1 --- 2022-aoc/src/d6.rs | 23 +++++++++++++++++++++++ 2022-aoc/src/lib.rs | 1 + 2 files changed, 24 insertions(+) create mode 100644 2022-aoc/src/d6.rs 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 }