diff --git a/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java b/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java index 641d308..9865d39 100644 --- a/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java +++ b/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java @@ -20,7 +20,6 @@ public class ChronospatialComputer { private int[] program; private int instructionPointer; private StringJoiner outJoiner; - private boolean allowReservedOperand; public ChronospatialComputer(List inputs) { a = Integer.parseInt(inputs.get(0).substring(12)); @@ -32,11 +31,10 @@ public ChronospatialComputer(List inputs) { } - public String solveA(boolean allowReservedOperand) { + public String solveA() { instructionPointer = 0; outJoiner = new StringJoiner(","); - this.allowReservedOperand = allowReservedOperand; int opcode; int operator; @@ -83,9 +81,6 @@ private int getComboOperand(int operator) { case 6: return c; default: - if (allowReservedOperand) { - return operator; - } throw new IllegalArgumentException("Invalid operator: "+operator); } } @@ -94,8 +89,6 @@ private void adv(int operand) { int comboOperand = getComboOperand(operand); int power = (int) Math.pow(2, comboOperand); a = a / power; - - // TODO es posible que haya que truncar. } private void bxl(int operand) { diff --git a/src/test/java/com/adventofcode/flashk/day17/Day17Test.java b/src/test/java/com/adventofcode/flashk/day17/Day17Test.java index c09489d..c08847d 100644 --- a/src/test/java/com/adventofcode/flashk/day17/Day17Test.java +++ b/src/test/java/com/adventofcode/flashk/day17/Day17Test.java @@ -2,7 +2,6 @@ import java.util.List; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; @@ -36,7 +35,7 @@ void part1Debug1Test() { List inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE); ChronospatialComputer chronospatialComputer = new ChronospatialComputer(inputs); - chronospatialComputer.solveA(false); + chronospatialComputer.solveA(); assertEquals(1, chronospatialComputer.getB()); } @@ -53,7 +52,7 @@ void part1Debug2Test() { ChronospatialComputer chronospatialComputer = new ChronospatialComputer(inputs); - assertEquals("0,1,2", chronospatialComputer.solveA(false)); + assertEquals("0,1,2", chronospatialComputer.solveA()); } @Test @@ -76,7 +75,7 @@ void part1Debug3Test() { // Program: 0,1,5,4,3,0 - assertEquals("4,2,5,6,7,7,7,7,3,1,0", chronospatialComputer.solveA(false)); + assertEquals("4,2,5,6,7,7,7,7,3,1,0", chronospatialComputer.solveA()); assertEquals(0, chronospatialComputer.getA()); } @@ -91,7 +90,7 @@ void part1Debug4Test() { List inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE_4); ChronospatialComputer chronospatialComputer = new ChronospatialComputer(inputs); - chronospatialComputer.solveA(true); + chronospatialComputer.solveA(); // Se permite el operador reservado porque en este caso, el input tiene un operator 7 que hay que debuggear. @@ -109,7 +108,7 @@ void part1Debug5Test() { List inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE_5); ChronospatialComputer chronospatialComputer = new ChronospatialComputer(inputs); - chronospatialComputer.solveA(false); + chronospatialComputer.solveA(); assertEquals(44354, chronospatialComputer.getB()); } @@ -126,7 +125,7 @@ public void testSolvePart1Sample() { ChronospatialComputer chronospatialComputer = new ChronospatialComputer(inputs); - assertEquals("4,6,3,5,6,3,5,2,1,0", chronospatialComputer.solveA(false)); + assertEquals("4,6,3,5,6,3,5,2,1,0", chronospatialComputer.solveA()); } @Test @@ -138,11 +137,10 @@ public void testSolvePart1Input() { // Read input file List inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE); + ChronospatialComputer chronospatialComputer = new ChronospatialComputer(inputs); - System.out.println("Solution: "+chronospatialComputer.solveA(false)); - // 3,4,5,0,5,4,1,5,0 -> Not valid - assertEquals("6,7,5,2,1,3,5,1,7",chronospatialComputer.solveA(false)); + assertEquals("6,7,5,2,1,3,5,1,7",chronospatialComputer.solveA()); }