Solve Part 2
This commit is contained in:
parent
6ce82f8d4d
commit
49316e33a7
36
src/main.rs
36
src/main.rs
@ -7,6 +7,7 @@ fn has_duplicates(slice: &[char]) -> bool
|
||||
(1..slice.len()).any(|i| slice[i..].contains(&slice[i - 1]))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn part1()
|
||||
{
|
||||
let mut last_char = 0usize;
|
||||
@ -36,6 +37,37 @@ fn part1()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
part1();
|
||||
fn part2()
|
||||
{
|
||||
let mut last_char = 0usize;
|
||||
|
||||
let mut buffer: Vec<char> = Vec::with_capacity(14);
|
||||
|
||||
for c in DATA.chars()
|
||||
{
|
||||
last_char += 1;
|
||||
|
||||
if buffer.len() == 14
|
||||
{
|
||||
buffer.remove(0);
|
||||
}
|
||||
|
||||
buffer.push(c);
|
||||
|
||||
if last_char < 14 {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !has_duplicates(buffer.as_slice())
|
||||
{
|
||||
println!("First start-of-packet marker at {}", last_char);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
//part1();
|
||||
part2();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user