2022 day6/rust: add solution

This commit is contained in:
Xiretza 2022-12-06 06:12:56 +01:00
parent a3bc63b6ee
commit 8859be752a
4 changed files with 46 additions and 0 deletions

View file

@ -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" }

View file

@ -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::<u8>::from_iter(cs.into_iter().copied()).len() == 4)
.unwrap();
println!("{:?}", i + 4);
let i = data
.as_bytes()
.windows(14)
.position(|cs| HashSet::<u8>::from_iter(cs.into_iter().copied()).len() == 14)
.unwrap();
println!("{:?}", i + 14);
}

7
Cargo.lock generated
View file

@ -503,6 +503,13 @@ dependencies = [
"regex", "regex",
] ]
[[package]]
name = "rust_2022_06"
version = "0.1.0"
dependencies = [
"aoc",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.11" version = "1.0.11"

View file

@ -15,4 +15,5 @@ members = [
"2022/day3/rust", "2022/day3/rust",
"2022/day4/rust", "2022/day4/rust",
"2022/day5/rust", "2022/day5/rust",
"2022/day6/rust",
] ]