-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.java
65 lines (59 loc) · 1.72 KB
/
Day25.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import com.horstmann.adventofcode.*;
void parse(Path path) throws IOException {
var lines = Files.readAllLines(path);
keys = new ArrayList<>();
locks = new ArrayList<>();
int i = 0;
while (i < lines.size()) {
var line = lines.get(i);
int j = i + 1;
while (j < lines.size() && !lines.get(j).isBlank()) j++;
var grid = CharGrid.parse(lines.subList(i, j));
var heights = new ArrayList<Integer>();
if (line.equals("#####")) {
for (int c = 0; c < grid.cols(); c++) {
int r = 1;
while (r < grid.rows() && grid.get(new Location(r, c)) == '#') r++;
heights.add(r - 1);
}
locks.add(heights);
} else {
for (int c = 0; c < grid.cols(); c++) {
int r = grid.rows() - 2;
while (r >= 0 && grid.get(new Location(r, c)) == '#') r--;
heights.add(grid.rows() - r - 2);
}
keys.add(heights);
}
i = j + 1;
}
}
List<List<Integer>> keys;
List<List<Integer>> locks;
boolean fit(List<Integer> key, List<Integer> lock) {
for (int i = 0; i < key.size(); i++) {
if (key.get(i) + lock.get(i) >= 6) return false;
}
return true;
}
Object part1() {
long count = 0;
for (var k : keys)
for (var l : locks)
if (fit(k, l))
count++;
return count;
}
Object part2() {
return null;
}
void main() throws IOException {
Util.time(() -> {
parse(Util.inputPath("a"));
IO.println(part1());
IO.println(part2());
parse(Util.inputPath("z"));
IO.println(part1());
IO.println(part2());
});
}