From: alex <> Date: Sun, 7 Dec 2025 22:12:12 +0000 (+0100) Subject: day07: small cleanup X-Git-Url: https://aoc.elinar.fr/?a=commitdiff_plain;h=c45bb6cf9b6cfd448470f57d15b02d72b62622eb;p=aoc_2025 day07: small cleanup --- diff --git a/src/day07.rs b/src/day07.rs index d18fdab..6c48630 100644 --- a/src/day07.rs +++ b/src/day07.rs @@ -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; + }); } });