diff --git a/2022/day6/rust/Cargo.toml b/2022/day6/rust/Cargo.toml new file mode 100644 index 0000000..126035d --- /dev/null +++ b/2022/day6/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust_2022_06" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aoc = { path = "../../../common/rust" } diff --git a/2022/day6/rust/src/main.rs b/2022/day6/rust/src/main.rs new file mode 100644 index 0000000..a8bd880 --- /dev/null +++ b/2022/day6/rust/src/main.rs @@ -0,0 +1,29 @@ +#![warn(clippy::pedantic)] + +use std::{ + collections::HashSet, + io::{stdin, Read}, +}; + +use aoc::*; + +fn main() { + let mut data = String::new(); + stdin().read_to_string(&mut data).unwrap(); + + let i = data + .as_bytes() + .windows(4) + .position(|cs| HashSet::::from_iter(cs.into_iter().copied()).len() == 4) + .unwrap(); + + println!("{:?}", i + 4); + + let i = data + .as_bytes() + .windows(14) + .position(|cs| HashSet::::from_iter(cs.into_iter().copied()).len() == 14) + .unwrap(); + + println!("{:?}", i + 14); +} diff --git a/Cargo.lock b/Cargo.lock index 276ab35..fc85520 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -503,6 +503,13 @@ dependencies = [ "regex", ] +[[package]] +name = "rust_2022_06" +version = "0.1.0" +dependencies = [ + "aoc", +] + [[package]] name = "ryu" version = "1.0.11" diff --git a/Cargo.toml b/Cargo.toml index f0083d5..a7a3b01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ members = [ "2022/day3/rust", "2022/day4/rust", "2022/day5/rust", + "2022/day6/rust", ]