Skip to content

Instantly share code, notes, and snippets.

@saolsen
Created December 6, 2022 13:20
Show Gist options
  • Save saolsen/5d1145b5a007ecad31c2618f49d4b535 to your computer and use it in GitHub Desktop.
Save saolsen/5d1145b5a007ecad31c2618f49d4b535 to your computer and use it in GitHub Desktop.
aoc 2022 day06
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