|
@@ -114,6 +114,13 @@ pub fn solve_part1() -> Result<u32, Box<Error>> {
|
114
|
114
|
Ok(find_largest_coord_area(grid))
|
115
|
115
|
}
|
116
|
116
|
|
|
117
|
+pub fn solve_part2() -> Result<u32, Box<Error>> {
|
|
118
|
+ let coords = read_coordinates(INPUT)?;
|
|
119
|
+ let boundary_coord = get_boundary_coordinate(&coords);
|
|
120
|
+ let grid = create_grid(boundary_coord);
|
|
121
|
+ Ok(region_closest_to_coordinates_size(grid, coords))
|
|
122
|
+}
|
|
123
|
+
|
117
|
124
|
fn read_coordinates(filename: &str) -> Result<Vec<Coordinate>, Box<Error>> {
|
118
|
125
|
let mut records: Vec<Coordinate> = Vec::new();
|
119
|
126
|
lazy_static! {
|
|
@@ -258,13 +265,32 @@ fn find_largest_coord_area(
|
258
|
265
|
*count += 1;
|
259
|
266
|
}
|
260
|
267
|
},
|
261
|
|
- GridPoint::Unfilled { x: _, y: _ } |
|
262
|
|
- GridPoint::Tied { x: _, y: _, closest_dist: _ } => {}
|
|
268
|
+ _ => ()
|
263
|
269
|
}
|
264
|
270
|
}
|
265
|
271
|
*point_count.values().max().unwrap_or(&0)
|
266
|
272
|
}
|
267
|
273
|
|
|
274
|
+fn region_closest_to_coordinates_size(grid: Grid, coords: Vec<Coordinate>) -> u32 {
|
|
275
|
+ let mut points_in_region = 0;
|
|
276
|
+ for point in grid.points.iter() {
|
|
277
|
+ match point {
|
|
278
|
+ GridPoint::Filled { x, y, closest_coord: _, closest_dist: _ } |
|
|
279
|
+ GridPoint::Tied { x, y, closest_dist: _ } |
|
|
280
|
+ GridPoint::Unfilled { x, y } => {
|
|
281
|
+ let mut sum = 0;
|
|
282
|
+ for coord in coords.iter() {
|
|
283
|
+ sum += manhattan_dist(coord.x, coord.y, *x, *y);
|
|
284
|
+ }
|
|
285
|
+ if sum < 10000 {
|
|
286
|
+ points_in_region += 1;
|
|
287
|
+ }
|
|
288
|
+ }
|
|
289
|
+ }
|
|
290
|
+ }
|
|
291
|
+ points_in_region
|
|
292
|
+}
|
|
293
|
+
|
268
|
294
|
#[cfg(test)]
|
269
|
295
|
mod tests {
|
270
|
296
|
use super::*;
|