Skip to content

Commit 0666513

Browse files
committed
Comments for 2018-06*
1 parent 3c14bbb commit 0666513

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

2018/06a/src/main.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Strategy: Identify the coordinates with infinite area by determining the
2+
// bounding box (inclusive) for the coordinates as a whole and then shrinking
3+
// it as follows:
4+
//
5+
// - For each side of the bounding box:
6+
// - Loop:
7+
// - Move the side one unit inwards.
8+
// - If there exists a point along the side whose closest coordinates
9+
// are all within the bounds, exit the loop.
10+
//
11+
// Afterwards, the coordinates outside the bounds are the ones with infinite
12+
// area, and the bounding box contains all points whose nearest coordinate is
13+
// one with finite area.
114
use adventutil::Input;
215
use adventutil::counter::Counter;
316
use adventutil::gridgeom::{Point, PointBounds};
@@ -14,6 +27,7 @@ fn solve(input: Input) -> u64 {
1427
let mut bounds = PointBounds::for_points(coords.iter().copied()).unwrap();
1528

1629
'minx: loop {
30+
bounds.min_x += 1;
1731
let mut points_outside = Vec::new();
1832
let mut points_inside = Vec::new();
1933
for &p in &coords {
@@ -41,10 +55,10 @@ fn solve(input: Input) -> u64 {
4155
}
4256
}
4357
}
44-
bounds.min_x += 1;
4558
}
4659

4760
'maxx: loop {
61+
bounds.max_x -= 1;
4862
let mut points_outside = Vec::new();
4963
let mut points_inside = Vec::new();
5064
for &p in &coords {
@@ -72,10 +86,10 @@ fn solve(input: Input) -> u64 {
7286
}
7387
}
7488
}
75-
bounds.max_x -= 1;
7689
}
7790

7891
'miny: loop {
92+
bounds.min_y += 1;
7993
let mut points_outside = Vec::new();
8094
let mut points_inside = Vec::new();
8195
for &p in &coords {
@@ -103,10 +117,10 @@ fn solve(input: Input) -> u64 {
103117
}
104118
}
105119
}
106-
bounds.min_y += 1;
107120
}
108121

109122
'maxy: loop {
123+
bounds.max_y -= 1;
110124
let mut points_outside = Vec::new();
111125
let mut points_inside = Vec::new();
112126
for &p in &coords {
@@ -134,7 +148,6 @@ fn solve(input: Input) -> u64 {
134148
}
135149
}
136150
}
137-
bounds.max_y -= 1;
138151
}
139152

140153
let mut counter = Counter::new();

2018/06b/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This naïve attempt really only gives the right answer because I got lucky
2+
// with the input. A correct solution would have to expand the bounding box to
3+
// include all possible points that satisfy the total distance condition, but I
4+
// don't have test cases for checking such a solution.
15
use adventutil::Input;
26
use adventutil::gridgeom::{Point, PointBounds};
37

0 commit comments

Comments
 (0)