small tweak (convers sum() to fold())
This commit is contained in:
1 file changed
+9
-12
+9
-12
@@ -77,19 +77,16 @@ fn count_overlapped_cells(segments: &[LineSegment], includ_diag: bool) -> usize
|
|||||||
segments
|
segments
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|s| s.is_horizontal_or_vertical() || includ_diag)
|
.filter(|s| s.is_horizontal_or_vertical() || includ_diag)
|
||||||
.map(|s| {
|
.fold(0, |acc, s| {
|
||||||
s.rasterize()
|
acc + s.rasterize().fold(0, |acc, (x, y)| -> usize {
|
||||||
.map(|(x, y)| -> usize {
|
cells[x as usize][y as usize] += 1;
|
||||||
cells[x as usize][y as usize] += 1;
|
if cells[x as usize][y as usize] == 2 {
|
||||||
if cells[x as usize][y as usize] == 2 {
|
acc + 1
|
||||||
1
|
} else {
|
||||||
} else {
|
acc
|
||||||
0
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
.sum::<usize>()
|
|
||||||
})
|
})
|
||||||
.sum::<usize>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn run() -> Result<(usize, usize)> {
|
pub(crate) fn run() -> Result<(usize, usize)> {
|
||||||
|
|||||||
Reference in new issue
Block a user