Skip to content

Commit 6ef74a0

Browse files
committed
Revert "java/2016/19: add solution for part 2"
This reverts commit 5fad405.
1 parent 5fad405 commit 6ef74a0

File tree

2 files changed

+29
-50
lines changed
  • java/src
    • main/java/com/github/saser/adventofcode/year2016/day21
    • test/java/com/github/saser/adventofcode/year2016/day21

2 files changed

+29
-50
lines changed

java/src/main/java/com/github/saser/adventofcode/year2016/day21/Day21.java

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.BufferedReader;
44
import java.io.Reader;
55
import java.util.Arrays;
6-
import java.util.Collections;
76
import java.util.List;
87
import java.util.regex.Matcher;
98
import java.util.regex.Pattern;
@@ -21,77 +20,52 @@ public static Result part2(Reader r) {
2120
}
2221

2322
private static Result solve(Reader r, int part) {
24-
var chars = (part == 1 ? "abcdefgh" : "fbgdceah").toCharArray();
23+
var chars = "abcdefgh".toCharArray();
2524
var instructions = new BufferedReader(r)
2625
.lines()
27-
.collect(Collectors.toList());
28-
apply(chars, instructions, part == 2);
26+
.collect(Collectors.toUnmodifiableList());
27+
apply(chars, instructions);
2928
return Result.ok(new String(chars));
3029
}
3130

32-
private static void apply(char[] chars, List<String> instructions, boolean reverse) {
31+
private static void apply(char[] chars, List<String> instructions) {
3332
var swapPositionRE = Pattern.compile("swap position (\\d+) with position (\\d+)");
3433
var swapLetterRE = Pattern.compile("swap letter (\\w) with letter (\\w)");
3534
var rotateStepsRE = Pattern.compile("rotate (left|right) (\\d+) steps?");
3635
var rotateLetterRE = Pattern.compile("rotate based on position of letter (\\w)");
3736
var reverseRE = Pattern.compile("reverse positions (\\d+) through (\\d+)");
3837
var moveRE = Pattern.compile("move position (\\d+) to position (\\d+)");
39-
if (reverse) {
40-
Collections.reverse(instructions);
41-
}
4238
for (var instruction : instructions) {
4339
Matcher matcher;
4440
matcher = swapPositionRE.matcher(instruction);
4541
if (matcher.matches()) {
4642
var x = Integer.parseInt(matcher.group(1));
4743
var y = Integer.parseInt(matcher.group(2));
48-
if (reverse) {
49-
swap(chars, y, x);
50-
} else {
51-
swap(chars, x, y);
52-
}
44+
swap(chars, x, y);
5345
continue;
5446
}
5547
matcher = swapLetterRE.matcher(instruction);
5648
if (matcher.matches()) {
5749
var x = find(chars, matcher.group(1).charAt(0));
5850
var y = find(chars, matcher.group(2).charAt(0));
59-
if (reverse) {
60-
swap(chars, y, x);
61-
} else {
62-
swap(chars, x, y);
63-
}
51+
swap(chars, x, y);
6452
continue;
6553
}
6654
matcher = rotateStepsRE.matcher(instruction);
6755
if (matcher.matches()) {
6856
var right = matcher.group(1).equals("right");
6957
var steps = Integer.parseInt(matcher.group(2));
70-
if (reverse) {
71-
right = !right;
72-
}
7358
rotate(chars, right, steps);
7459
continue;
7560
}
7661
matcher = rotateLetterRE.matcher(instruction);
7762
if (matcher.matches()) {
7863
var index = find(chars, matcher.group(1).charAt(0));
79-
int steps;
80-
if (reverse) {
81-
if (index == 0) {
82-
steps = 1;
83-
} else if (index % 2 == 1) {
84-
steps = index / 2 + 1;
85-
} else {
86-
steps = 5 + index / 2;
87-
}
88-
} else {
89-
steps = 1 + index;
90-
if (index >= 4) {
91-
steps++;
92-
}
64+
var steps = 1 + index;
65+
if (index >= 4) {
66+
steps++;
9367
}
94-
rotate(chars, !reverse, steps);
68+
rotate(chars, true, steps);
9569
continue;
9670
}
9771
matcher = reverseRE.matcher(instruction);
@@ -105,11 +79,7 @@ private static void apply(char[] chars, List<String> instructions, boolean rever
10579
if (matcher.matches()) {
10680
var x = Integer.parseInt(matcher.group(1));
10781
var y = Integer.parseInt(matcher.group(2));
108-
if (reverse) {
109-
move(chars, y, x);
110-
} else {
111-
move(chars, x, y);
112-
}
82+
move(chars, x, y);
11383
continue;
11484
}
11585
throw new IllegalArgumentException(String.format("invalid instruction: %s", instruction));

java/src/test/java/com/github/saser/adventofcode/year2016/day21/Day21Test.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ public void part1Actual() throws IOException {
1818
}
1919
}
2020

21-
@Test
22-
public void part2Actual() throws IOException {
23-
try (var input = new FileReader("inputs/2016/21")) {
24-
var output = "gcehdbfa";
25-
var result = Day21.part2(input);
26-
Assert.assertEquals("no error", "", result.error);
27-
Assert.assertEquals("correct output", output, result.answer);
28-
}
29-
}
21+
// @Test
22+
// public void part2Example() {
23+
// var input = new StringReader("");
24+
// var output = "";
25+
// var result = Day21.part2(input);
26+
// Assert.assertEquals("no error", "", result.error);
27+
// Assert.assertEquals("correct output", output, result.answer);
28+
// }
29+
30+
// @Test
31+
// public void part2Actual() throws IOException {
32+
// try (var input = new FileReader("inputs/2016/21")) {
33+
// var output = "";
34+
// var result = Day21.part2(input);
35+
// Assert.assertEquals("no error", "", result.error);
36+
// Assert.assertEquals("correct output", output, result.answer);
37+
// }
38+
// }
3039
}

0 commit comments

Comments
 (0)