diff options
Diffstat (limited to '2022/rust/day06/src')
-rw-r--r-- | 2022/rust/day06/src/main.rs | 27 |
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; + } + } +} |