-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday12.java
More file actions
27 lines (26 loc) · 911 Bytes
/
Copy pathday12.java
File metadata and controls
27 lines (26 loc) · 911 Bytes
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
import static java.lang.IO.*;
import static java.lang.Integer.parseInt;
void main() {
var line = readln();
int res = 0, n = 0;
var tiles = new HashMap<Integer, Integer>();
var re = Pattern.compile("\\d+");
while (line != null) {
if (line.length() == 2 && line.charAt(1) == ':') {
tiles.put(n++, (int) (readln() + readln() + readln()).chars().filter(c -> c == '#').count());
} else if (line.contains("x")) {
var nums = re.matcher(line).results().map(r -> parseInt(r.group())).toList();
var area = nums.get(0) * nums.get(1);
nums = nums.stream().skip(2).toList();
var s = 0;
for (var i = 0; i < nums.size(); i++) {
s += nums.get(i) * tiles.get(i);
}
if (s <= area) {
res++;
}
}
line = readln();
}
println(res);
}