]> aoc.elinar.fr Git - aoc_2025/commitdiff
day07: small cleanup
authoralex <>
Sun, 7 Dec 2025 22:12:12 +0000 (23:12 +0100)
committeralex <>
Sun, 7 Dec 2025 22:12:12 +0000 (23:12 +0100)
src/day07.rs

index d18fdab5ee88e9e86520e0434b067204dcc81cd1..6c48630221738f03e599b805b9b676e12e3bba5d 100644 (file)
@@ -55,7 +55,7 @@ impl Puzzle {
             .filter(|(_, v)| v.1 && v.0 == '.')
             .map(|(k, _)| *k)
             .collect();
-        beams_pos.sort_by(|a, b| a.cmp(&b));
+        beams_pos.sort();
 
         // keep track of the number of timelines for each visited location
         let mut beams_timelines: HashMap<(usize, usize), u64> = self.map.iter()
@@ -72,25 +72,20 @@ impl Puzzle {
         // compute the number of timelines per line
         beams_pos.iter()
             .for_each(|pos| {
-                let timeline = *beams_timelines.get(&pos).unwrap();
+                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
-                    match next_char {
-                        '.' => {
-                            let next_timeline = beams_timelines.get_mut(&next_pos).unwrap();
-                            *next_timeline += timeline;
-                        },
-                        '^' => {
-                            [next_pos.1 - 1, next_pos.1 + 1].into_iter()
-                                .for_each(|j| {
-                                    let p = (next_pos.0, j);
-                                    let next_timeline = beams_timelines.get_mut(&p).unwrap();
-                                    *next_timeline += timeline;
-                                });
-                        },
+                    let next_pos = match next_char {
+                        '.' => vec![(pos.0 + 1, pos.1)],
+                        '^' => vec![(pos.0 + 1, pos.1 - 1), (pos.0 + 1, pos.1 + 1)],
                         _ => unreachable!(),
-                    }
+                    };
+                    next_pos.iter()
+                        .for_each(|p| {
+                            let next_timeline = beams_timelines.get_mut(p).unwrap();
+                            *next_timeline += timeline;
+                        });
                 }
             });