18 lines
421 B
Rust
18 lines
421 B
Rust
use itertools::Itertools;
|
|
|
|
fn begin_datagram(datagram: &str, size: usize) -> usize {
|
|
size + datagram
|
|
.as_bytes()
|
|
.windows(size)
|
|
.position(|window| window.iter().tuple_combinations().all(|(a, b)| a != b))
|
|
.unwrap()
|
|
}
|
|
|
|
pub fn solve_part1(content: &str) -> i32 {
|
|
begin_datagram(content, 4) as i32
|
|
}
|
|
|
|
pub fn solve_part2(content: &str) -> i32 {
|
|
begin_datagram(content, 14) as i32
|
|
}
|