Skip to content

Instantly share code, notes, and snippets.

@lukesteensen
Created December 9, 2017 16:14
Show Gist options
  • Save lukesteensen/45f213d7702dedb2433c39582403f4e7 to your computer and use it in GitHub Desktop.
Save lukesteensen/45f213d7702dedb2433c39582403f4e7 to your computer and use it in GitHub Desktop.
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