aboutsummaryrefslogtreecommitdiff
path: root/2022/rust/day06/src/main.rs
diff options
context:
space:
mode:
authorj-james2022-12-06 06:54:35 +0000
committerj-james2022-12-06 06:54:35 +0000
commit216616ab804a9b8df86511f356f692db5406d654 (patch)
tree9e01ee175059e2bc76ce94c55d9685139c0e9fc5 /2022/rust/day06/src/main.rs
parentfbf08093a62a6c99e14df0b001d4acc5459e8e06 (diff)
Day Six
Diffstat (limited to '2022/rust/day06/src/main.rs')
-rw-r--r--2022/rust/day06/src/main.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/2022/rust/day06/src/main.rs b/2022/rust/day06/src/main.rs
new file mode 100644
index 0000000..b5f42cc
--- /dev/null
+++ b/2022/rust/day06/src/main.rs
@@ -0,0 +1,27 @@
+use std::collections::HashSet;
+use std::env;
+use std::fs;
+
+fn main() {
+ let args = env::args().nth(1).expect("missing input");
+ let input = fs::read_to_string(args).unwrap();
+ let signal: Vec<char> = input.trim().chars().collect();
+
+ let depth = 4;
+ for (i, c) in signal.windows(depth).enumerate() {
+ // why can rust not infer the type of HashSet?
+ // https://stackoverflow.com/questions/62949404/
+ if HashSet::<_>::from_iter(c).len() == depth {
+ println!("{}", i + depth);
+ break;
+ }
+ }
+
+ let depth = 14;
+ for (i, c) in signal.windows(depth).enumerate() {
+ if HashSet::<_>::from_iter(c).len() == depth {
+ println!("{}", i + depth);
+ break;
+ }
+ }
+}