Created
December 6, 2022 13:20
-
-
Save saolsen/5d1145b5a007ecad31c2618f49d4b535 to your computer and use it in GitHub Desktop.
aoc 2022 day06
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
fn main() { | |
let input = include_str!("day06_input.txt"); | |
let data: Vec<char> = input.chars().collect(); | |
// just let HashSet do all the work | |
let mut message_set = HashSet::new(); | |
for i in 0..data.len() { | |
if i >= 13 { | |
message_set.clear(); | |
for j in i - 13..=i { | |
message_set.insert(data[j]); | |
} | |
if message_set.len() == 14 { | |
eprintln!("start-of-message marker at {}", i + 1); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment