Skip to content

Commit fac8861

Browse files
committed
Improve year 2022 day8
1 parent 4960de4 commit fac8861

File tree

1 file changed

+3
-10
lines changed
  • year2022/src/main/java/dev/linl33/adventofcode/year2022

1 file changed

+3
-10
lines changed

year2022/src/main/java/dev/linl33/adventofcode/year2022/Day8.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ public Integer part1(@NotNull BufferedReader reader) {
6464
if (curr > max) {
6565
max = curr;
6666
maxY = y;
67-
68-
if (!visible[x + y * cols]) {
69-
visible[x + y * cols] = true;
70-
visibleTrees++;
71-
}
67+
visibleTrees += visible[x + y * cols] ? 0 : 1;
7268
}
7369
}
7470

@@ -78,10 +74,7 @@ public Integer part1(@NotNull BufferedReader reader) {
7874
var curr = input[y].charAt(x);
7975
if (curr > max) {
8076
max = curr;
81-
if (!visible[x + y * cols]) {
82-
visible[x + y * cols] = true;
83-
visibleTrees++;
84-
}
77+
visibleTrees += visible[x + y * cols] ? 0 : 1;
8578
}
8679
}
8780
}
@@ -129,7 +122,7 @@ public Integer part2(@NotNull BufferedReader reader) {
129122
// look left
130123
score *= treeX - backRef[treeX];
131124

132-
var maxPotential = (((rows - 1) / 2) * ((rows - 1) - (rows - 1) / 2)) * score;
125+
var maxPotential = (treeY - colBackRef[colBackRefPointer]) * ((rows - 1) - treeY) * score;
133126
if (maxPotential <= max) {
134127
skippedColumns[treeY] = true;
135128
continue;

0 commit comments

Comments
 (0)