]> aoc.elinar.fr Git - aoc_2025/commitdiff
day07: refactoring
authoralex <>
Mon, 8 Dec 2025 08:44:30 +0000 (09:44 +0100)
committeralex <>
Mon, 8 Dec 2025 08:44:30 +0000 (09:44 +0100)
src/day07.rs

index 6c48630221738f03e599b805b9b676e12e3bba5d..7946d4a0bb82297984402c1b487116587665cde5 100644 (file)
@@ -27,8 +27,7 @@ impl Puzzle {
         let mut beam: Vec<(usize, usize)> = Vec::new();
         beam.push((self.start.0 + 1, self.start.1));
         while let Some(pos) = beam.pop() {
-            if self.map.contains_key(&pos) {
-                let location = self.map.get_mut(&pos).unwrap();
+            if let Some(location) = self.map.get_mut(&pos) {
                 if location.1 {
                     continue;
                 }
@@ -73,10 +72,8 @@ impl Puzzle {
         beams_pos.iter()
             .for_each(|pos| {
                 let timeline = *beams_timelines.get(pos).unwrap();
-                let next_pos = (pos.0 + 1, pos.1);
-                if self.map.contains_key(&next_pos) {
-                    let next_char = self.map.get_mut(&next_pos).unwrap().0; // it exists
-                    let next_pos = match next_char {
+                if let Some(next) = self.map.get_mut(&(pos.0 + 1, pos.1)) {
+                    let next_pos = match next.0 {
                         '.' => vec![(pos.0 + 1, pos.1)],
                         '^' => vec![(pos.0 + 1, pos.1 - 1), (pos.0 + 1, pos.1 + 1)],
                         _ => unreachable!(),