~swaits/aoc2021

cd0c64b1528e02db8bad10ebf24037769959b0c3 — Stephen Waits 1 year, 9 months ago d1dcb51
small tweak (convers sum() to fold())
1 files changed, 9 insertions(+), 12 deletions(-)

M src/day05.rs
M src/day05.rs => src/day05.rs +9 -12
@@ 77,19 77,16 @@ fn count_overlapped_cells(segments: &[LineSegment], includ_diag: bool) -> usize 
    segments
        .iter()
        .filter(|s| s.is_horizontal_or_vertical() || includ_diag)
        .map(|s| {
            s.rasterize()
                .map(|(x, y)| -> usize {
                    cells[x as usize][y as usize] += 1;
                    if cells[x as usize][y as usize] == 2 {
                        1
                    } else {
                        0
                    }
                })
                .sum::<usize>()
        .fold(0, |acc, s| {
            acc + s.rasterize().fold(0, |acc, (x, y)| -> usize {
                cells[x as usize][y as usize] += 1;
                if cells[x as usize][y as usize] == 2 {
                    acc + 1
                } else {
                    acc
                }
            })
        })
        .sum::<usize>()
}

pub(crate) fn run() -> Result<(usize, usize)> {