Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 79e658f

Browse files
committed
missed part 2 of day 2
1 parent 04fc235 commit 79e658f

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/com/togetherjava/adventofcode/Day2.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,26 @@ public static void main(String[] args) {
1212
for (int i = 0; i < data.length; i++) {
1313
data[i] = Integer.parseInt(input[i]);
1414
}
15-
data[1] = 12;
16-
data[2] = 2;
15+
System.out.println("Part 1)");
16+
int[] part1 = Arrays.copyOf(data, data.length);
17+
//part 1 noun = 2 verb = 12
18+
System.out.println(calculate(part1, 12, 2)[0]);
19+
for(int verb = 0; verb < 100; verb++) {
20+
for(int noun = 0; noun < 100; noun++) {
21+
int[] part2 = Arrays.copyOf(data, data.length);
22+
int[] temp = calculate(part2, noun, verb);
23+
if(temp[0] == 19690720) {
24+
System.out.println("Part 2)");
25+
System.out.printf("FOUND NOUN = %d VERB = %d\n", noun, verb);
26+
System.out.printf("100 * %d + %d = %d", noun, verb, 100 * noun + verb);
27+
}
28+
}
29+
}
30+
}
31+
32+
public static int[] calculate(int[] data, int noun, int verb) {
33+
data[1] = noun;
34+
data[2] = verb;
1735
int i = 0;
1836
while (i < data.length) {
1937
int opcode = data[i];
@@ -34,11 +52,9 @@ public static void main(String[] args) {
3452
data[positionToStore] = a * b;
3553
i += 4;
3654
} else if (opcode == 99) {
37-
System.out.println("Opcode 99 reached - terminating");
3855
break;
3956
}
4057
}
41-
System.out.println(Arrays.toString(data).replaceAll(" ", ""));
42-
System.out.println("Number at position 0 is " + data[0]);
58+
return data;
4359
}
4460
}

0 commit comments

Comments
 (0)