Created
December 9, 2017 16:14
-
-
Save lukesteensen/45f213d7702dedb2433c39582403f4e7 to your computer and use it in GitHub Desktop.
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 main() { | |
let mut input = include_str!("../../day9.txt").chars(); | |
let mut gc = 0; | |
let mut garbage = false; | |
let mut groups = vec![]; | |
let mut open_groups = 0; | |
while let Some(c) = input.next() { | |
if !garbage { | |
match c { | |
'{' => open_groups += 1, | |
'}' => { | |
groups.push(open_groups); | |
open_groups -= 1; | |
}, | |
'<' => { garbage = true }, | |
'!' => { input.next(); }, | |
_ => {}, | |
} | |
} else { | |
match c { | |
'>' => { garbage = false }, | |
'!' => { input.next(); }, | |
_ => { gc += 1 }, | |
} | |
} | |
} | |
println!("{}", groups.iter().sum::<i32>()); | |
println!("{}", gc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment