Created
January 4, 2019 22:36
-
-
Save smarnach/6fc075561ef880cc1a58d5d2c63347e6 to your computer and use it in GitHub Desktop.
Advent of Code Day 5
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
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