1
0
aoc-2022/day6/src/main.rs
2022-12-23 21:20:23 +00:00

33 lines
856 B
Rust

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;
}
}
}
}