Skip to content

Commit 1c4f010

Browse files
committed
AoC 2022 Day 10 - java - faster
1 parent 4f6e0e8 commit 1c4f010

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Diff for: src/main/java/AoC2022_10.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ private int check(final int cycles, final int x) {
6464
}
6565

6666
private char draw(final int cycles, final int x) {
67-
if (Range.rangeClosed(x - 1, x + 1, 1).contains(cycles % 40)) {
68-
return FILL;
69-
} else {
70-
return EMPTY;
71-
}
67+
return Math.abs(x - cycles % 40) <= 1 ? FILL : EMPTY;
7268
}
7369

7470
private List<String> getPixels() {
@@ -89,7 +85,9 @@ public Integer solvePart1() {
8985

9086
@Override
9187
public String solvePart2() {
92-
return OCR.convert6(Grid.from(getPixels()), FILL, EMPTY);
88+
final List<String> pixels = getPixels();
89+
pixels.forEach(this::log);
90+
return OCR.convert6(Grid.from(pixels), FILL, EMPTY);
9391
}
9492

9593
public static void main(final String[] args) throws Exception {
@@ -107,7 +105,7 @@ public static void main(final String[] args) throws Exception {
107105
final List<String> inputData = puzzle.getInputData();
108106
puzzle.check(
109107
() -> lap("Part 1", AoC2022_10.create(inputData)::solvePart1),
110-
() -> lap("Part 2", AoC2022_10.create(inputData)::solvePart2)
108+
() -> lap("Part 2", AoC2022_10.createDebug(inputData)::solvePart2)
111109
);
112110
}
113111

0 commit comments

Comments
 (0)