((x,y): (usize,usize), coords: &mut HashSet<(usize,usize)>)
| 13 | } |
| 14 | |
| 15 | fn remove_component((x,y): (usize,usize), coords: &mut HashSet<(usize,usize)>) -> usize { |
| 16 | if !coords.remove(&(x,y)) { |
| 17 | return 0; |
| 18 | } |
| 19 | 1 + [(x-1,y),(x+1,y),(x,y-1),(x,y+1)].iter() |
| 20 | .map(|&neighbour| remove_component(neighbour, coords)) |
| 21 | .sum::<usize>() |
| 22 | } |
| 23 | |
| 24 | fn part2(grid: &[Vec<u8>]) -> usize { |
| 25 | let mut points = (0..grid[0].len()).cartesian_product(0..grid.len()) |