Skip to content

Instantly share code, notes, and snippets.

@smarnach
Created January 4, 2019 22:36
Show Gist options
  • Save smarnach/6fc075561ef880cc1a58d5d2c63347e6 to your computer and use it in GitHub Desktop.
Save smarnach/6fc075561ef880cc1a58d5d2c63347e6 to your computer and use it in GitHub Desktop.
Advent of Code Day 5
fn annihilate(polymer: &[u8], remove: u8) -> Vec<u8> {
let mut result = Vec::new();
for &c in polymer {
if c == remove || c ^ 32 == remove {
continue;
}
if result.is_empty() || result.last().unwrap() ^ c != 32 {
result.push(c);
} else {
result.pop();
}
}
result
}
fn main() {
let polymer = include_bytes!("day05.in");
let f = |c| annihilate(polymer, c).len();
println!("{}", f(0));
println!("{}", (b'a'..=b'z').map(f).min().unwrap());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment