From dd86a85883cd98c825c75f5a814000294868216e Mon Sep 17 00:00:00 2001 From: Flashk Date: Fri, 27 Dec 2024 08:52:07 +0100 Subject: [PATCH] tests: adjusts tests and possible bugs for day 17 --- .../flashk/day17/ChronospatialComputer.java | 29 ++++++------------- .../adventofcode/flashk/day17/Program.java | 1 - .../adventofcode/flashk/day17/Day17Test.java | 6 ++-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java b/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java index 413acf9..9acb2e8 100644 --- a/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java +++ b/src/main/java/com/adventofcode/flashk/day17/ChronospatialComputer.java @@ -4,18 +4,13 @@ import org.apache.commons.lang3.StringUtils; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.StringJoiner; -import java.util.regex.Pattern; @Getter public class ChronospatialComputer { - private static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d*)*"); - private long a; private long b; private long c; @@ -53,7 +48,6 @@ public String solveA() { instructionPointer += 2; } - } return outJoiner.toString(); @@ -63,23 +57,18 @@ public long solveB() { // https://www.reddit.com/r/adventofcode/comments/1hn01ke/2024_day_17_part_2_code_works_until_certain/ - return findRegistryA2(0, StringUtils.EMPTY, StringUtils.EMPTY); + return findRegistryA(0, StringUtils.EMPTY, StringUtils.EMPTY); } - private long findRegistryA2(int digit, String currentOctalNumber, String output) { - - /* - if(digit == 11) { - System.out.printf("oct: %s -> %s", currentOctalNumber, output); - System.out.println(); - }*/ + private long findRegistryA(int digit, String currentOctalNumber, String output) { if(!expectedProgram.endsWith(output)) { return -1; - } else if(digit == program.length) { - long result = Long.parseLong(currentOctalNumber, 8); - return expectedProgram.equals(output) ? result : -1; + } else if(expectedProgram.equals(output)){ + return Long.parseLong(currentOctalNumber, 8); + } else if(currentOctalNumber.length() == 16) { + return -1; } for(int octalDigit = 0; octalDigit < 8; octalDigit++) { @@ -87,7 +76,7 @@ private long findRegistryA2(int digit, String currentOctalNumber, String output) this.b = 0; this.c = 0; String partialOutput = solveA(); - long result = findRegistryA2(digit+1, currentOctalNumber+octalDigit, partialOutput); + long result = findRegistryA(digit+1, currentOctalNumber+octalDigit, partialOutput); if(result != -1) { return result; } @@ -156,12 +145,12 @@ private void out(int operand) { private void bdv(int operand) { long comboOperand = getComboOperand(operand); - b = a / (int) Math.pow(2, comboOperand); + b = a / (long) Math.pow(2, comboOperand); } private void cdv(int operand) { long comboOperand = getComboOperand(operand); - c = a / (int) Math.pow(2, comboOperand); + c = a / (long) Math.pow(2, comboOperand); } private long xor(long a, long b) { diff --git a/src/main/java/com/adventofcode/flashk/day17/Program.java b/src/main/java/com/adventofcode/flashk/day17/Program.java index 88e0ac1..ba82801 100644 --- a/src/main/java/com/adventofcode/flashk/day17/Program.java +++ b/src/main/java/com/adventofcode/flashk/day17/Program.java @@ -2,7 +2,6 @@ import org.apache.commons.lang3.StringUtils; -import java.util.Arrays; import java.util.List; import java.util.StringJoiner; diff --git a/src/test/java/com/adventofcode/flashk/day17/Day17Test.java b/src/test/java/com/adventofcode/flashk/day17/Day17Test.java index 05e6c52..168ff5d 100644 --- a/src/test/java/com/adventofcode/flashk/day17/Day17Test.java +++ b/src/test/java/com/adventofcode/flashk/day17/Day17Test.java @@ -173,7 +173,7 @@ public void testSolvePart2Sample() { @Tag(TestTag.PART_2) @Tag(TestTag.INPUT) @DisplayName(TestDisplayName.PART_2_INPUT) - @Disabled("[Disabled] Day 17 - testSolvePart2Input: Work in Progress") + @Disabled("Day 17 - Doesn't give the expected output") public void testSolvePart2Input() { // Read input file @@ -189,8 +189,8 @@ public void testSolvePart2Input() { @Order(4) @Tag(TestTag.PART_2) @Tag(TestTag.INPUT) - @DisplayName(TestDisplayName.PART_2_INPUT) - public void part2InputWithProgramTest() { + @DisplayName(TestDisplayName.PART_2_INPUT + " - Program") + void part2InputWithProgramTest() { // Read input file List inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);