2022 day6/rust: add solution
This commit is contained in:
parent
a3bc63b6ee
commit
8859be752a
4 changed files with 46 additions and 0 deletions
9
2022/day6/rust/Cargo.toml
Normal file
9
2022/day6/rust/Cargo.toml
Normal 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" }
|
29
2022/day6/rust/src/main.rs
Normal file
29
2022/day6/rust/src/main.rs
Normal 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
7
Cargo.lock
generated
|
@ -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"
|
||||||
|
|
|
@ -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",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue