1
0
This commit is contained in:
2022-12-23 21:20:23 +00:00
parent 87f14bbf0c
commit 52a17ff632
4 changed files with 43 additions and 1 deletions

32
day6/src/main.rs Normal file
View File

@ -0,0 +1,32 @@
extern crate queue;
use std::collections::HashSet;
use queue::Queue;
fn main() {
const INPUT: &str = include_str!("../sample_input.txt");
let mut buf: Queue<char> = Queue::with_capacity(4);
let mut msg_buf: Queue<char> = Queue::with_capacity(14);
let mut found_start = false;
for (i, c) in INPUT.chars().enumerate() {
if buf.force_queue(c) == 4 && !found_start {
let x = HashSet::<&char>::from_iter(buf.vec().iter()).len();
if x == 4 {
println!("{} {:?}", i + 1, buf);
found_start = true;
}
}
if msg_buf.force_queue(c) == 14 {
let x = HashSet::<&char>::from_iter(msg_buf.vec().iter()).len();
if x == 14 {
println!("{} {:?}", i + 1, msg_buf);
break;
}
}
}
}