diff --git a/examples/day06_1.rs b/examples/day06_1.rs new file mode 100644 index 0000000..bcc6f0a --- /dev/null +++ b/examples/day06_1.rs @@ -0,0 +1,13 @@ +use std::collections::HashSet; + +fn main() { + let line = std::io::stdin().lines().next().unwrap().unwrap(); + let chars: Vec = line.chars().collect(); + for (i, window) in chars.windows(4).enumerate() { + let set: HashSet = HashSet::from_iter(window.iter().map(|x| *x)); + if set.len() == 4 { + println!("{}", i + 4); + return + } + } +} diff --git a/examples/day06_2.rs b/examples/day06_2.rs new file mode 100644 index 0000000..62eb59c --- /dev/null +++ b/examples/day06_2.rs @@ -0,0 +1,13 @@ +use std::collections::HashSet; + +fn main() { + let line = std::io::stdin().lines().next().unwrap().unwrap(); + let chars: Vec = line.chars().collect(); + for (i, window) in chars.windows(14).enumerate() { + let set: HashSet = HashSet::from_iter(window.iter().map(|x| *x)); + if set.len() == 14 { + println!("{}", i + 14); + return + } + } +}