-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDay25.java
38 lines (31 loc) · 1.19 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
package com.sbaars.adventofcode.year24.days;
import com.sbaars.adventofcode.year24.Day2024;
import com.sbaars.adventofcode.common.grid.InfiniteGrid;
import static com.sbaars.adventofcode.util.MuUtils.allPairs;
import java.util.*;
public class Day25 extends Day2024 {
public Day25() {
super(25);
}
public static void main(String[] args) {
new Day25().printParts();
}
@Override
public Object part1() {
List<InfiniteGrid> locks = new ArrayList<>();
List<InfiniteGrid> keys = new ArrayList<>();
dayStream("\n\n").map(InfiniteGrid::new).forEach(g -> {
long rows = g.height() - 1;
if (g.stream().filter(l -> l.y == 0).allMatch(l -> g.getChar(l) == '#') && g.stream().filter(l -> l.y == rows).allMatch(l -> g.getChar(l) == '.')) {
locks.add(g);
} else if (g.stream().filter(l -> l.y == 0).allMatch(l -> g.getChar(l) == '.') && g.stream().filter(l -> l.y == rows).allMatch(l -> g.getChar(l) == '#')) {
keys.add(g);
}
});
return allPairs(locks, keys).filter((l, k) -> l.stream().noneMatch(loc -> l.get(loc).orElse(' ') == '#' && k.get(loc).orElse(' ') == '#')).count();
}
@Override
public Object part2() {
return "The End.";
}
}