Skip to content

Commit

Permalink
tests: adjusts tests and possible bugs for day 17
Browse files Browse the repository at this point in the history
  • Loading branch information
Flashky committed Dec 27, 2024
1 parent c5494e2 commit dd86a85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +48,6 @@ public String solveA() {
instructionPointer += 2;
}


}

return outJoiner.toString();
Expand All @@ -63,31 +57,26 @@ 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++) {
this.a = Long.parseLong(currentOctalNumber + octalDigit, 8);
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;
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/adventofcode/flashk/day17/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/adventofcode/flashk/day17/Day17Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);
Expand Down

0 comments on commit dd86a85

Please sign in to comment.