-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDay21.java
80 lines (62 loc) · 2.51 KB
/
Day21.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package aoc19;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import myutils19.IntCodeComputer;
import myutils19.StaticUtils;
public class Day21 {
private List<Long> initialProgram;
public Day21(File inputFile) {
initialProgram = StaticUtils.commaSeperatedLongFileToList(inputFile);
}
// solved using a 4 variable truth table
// jump if ~(A + B + C) + D
public int run1() {
IntCodeComputer computer = new IntCodeComputer(new ArrayList<>(initialProgram));
computer.run();
computer.setInputValues('N', 'O', 'T', ' ', 'A', ' ', 'T', 10);
computer.setInputValues('N', 'O', 'T', ' ', 'B', ' ', 'J', 10);
computer.setInputValues('O', 'R', ' ', 'T', ' ', 'J', 10);
computer.setInputValues('N', 'O', 'T', ' ', 'C', ' ', 'T', 10);
computer.setInputValues('O', 'R', ' ', 'T', ' ', 'J', 10);
computer.setInputValues('A', 'N', 'D', ' ', 'D', ' ', 'J', 10);
computer.setInputValues('W', 'A', 'L', 'K', 10);
computer.run();
Queue<Long> output = computer.outputValues();
int result = 0;
while (!output.isEmpty()) {
result = output.poll().intValue();
}
return result;
}
// pretty much the same as above, we only need to make sure that the next jump
// is also possible, eg, by checking E and H, this might not work for ALL
// inputs, if it doesn't make sure to also take a look at F and I
public int run2() {
IntCodeComputer computer = new IntCodeComputer(new ArrayList<>(initialProgram));
computer.run();
computer.setInputValues('N', 'O', 'T', ' ', 'A', ' ', 'T', 10);
computer.setInputValues('N', 'O', 'T', ' ', 'B', ' ', 'J', 10);
computer.setInputValues('O', 'R', ' ', 'T', ' ', 'J', 10);
computer.setInputValues('N', 'O', 'T', ' ', 'C', ' ', 'T', 10);
computer.setInputValues('O', 'R', ' ', 'T', ' ', 'J', 10);
computer.setInputValues('A', 'N', 'D', ' ', 'D', ' ', 'J', 10);
computer.setInputValues('N', 'O', 'T', ' ', 'J', ' ', 'T', 10);
computer.setInputValues('O', 'R', ' ', 'E', ' ', 'T', 10);
computer.setInputValues('O', 'R', ' ', 'H', ' ', 'T', 10);
computer.setInputValues('A', 'N', 'D', ' ', 'T', ' ', 'J', 10);
computer.setInputValues('R', 'U', 'N', 10);
computer.run();
Queue<Long> output = computer.outputValues();
int result = 0;
while (!output.isEmpty()) {
result = output.poll().intValue();
}
return result;
}
public static void main(String[] args) {
Day21 test = new Day21(new File("C:\\Users\\Timucin\\Desktop\\Advent of code 2019\\Day 21\\InputFile.txt"));
System.out.println(test.run2());
}
}