day 06
This commit is contained in:
parent
d93ee04c32
commit
1cce3469bb
2 changed files with 26 additions and 0 deletions
13
examples/day06_1.rs
Normal file
13
examples/day06_1.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
fn main() {
|
||||
let line = std::io::stdin().lines().next().unwrap().unwrap();
|
||||
let chars: Vec<char> = line.chars().collect();
|
||||
for (i, window) in chars.windows(4).enumerate() {
|
||||
let set: HashSet<char> = HashSet::from_iter(window.iter().map(|x| *x));
|
||||
if set.len() == 4 {
|
||||
println!("{}", i + 4);
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
13
examples/day06_2.rs
Normal file
13
examples/day06_2.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
fn main() {
|
||||
let line = std::io::stdin().lines().next().unwrap().unwrap();
|
||||
let chars: Vec<char> = line.chars().collect();
|
||||
for (i, window) in chars.windows(14).enumerate() {
|
||||
let set: HashSet<char> = HashSet::from_iter(window.iter().map(|x| *x));
|
||||
if set.len() == 14 {
|
||||
println!("{}", i + 14);
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue