More targeted dedup on day 20
authorJustin Worthe <justin@worthe-it.co.za>
Thu, 20 Dec 2018 06:11:41 +0000 (08:11 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Thu, 20 Dec 2018 06:11:41 +0000 (08:11 +0200)
src/bin/day_20.rs

index b9706d5..6486d72 100644 (file)
@@ -49,8 +49,6 @@ fn populate_rooms(input: &str) -> HashMap<(i32, i32), Room> {
     let mut coord_stack: Vec<(Vec<(i32, i32)>, Vec<(i32, i32)>)> = Vec::new();
 
     for c in input.chars() {
-        coords.sort();
-        coords.dedup();
         match c {
             '^' | '$' => {},
             'E' => {
@@ -91,6 +89,8 @@ fn populate_rooms(input: &str) -> HashMap<(i32, i32), Room> {
             ')' => {
                 coord_stack.last_mut().unwrap().1.append(&mut coords);
                 coords = coord_stack.pop().unwrap().1;
+                coords.sort();
+                coords.dedup();
             },
             c => {
                 panic!("Unknown character {}", c);