-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathDay21.java
51 lines (45 loc) · 1.15 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
package com.sbaars.adventofcode.year19.days;
import com.sbaars.adventofcode.year19.Day2019;
import com.sbaars.adventofcode.year19.intcode.IntcodeComputer;
public class Day21 extends Day2019 {
public Day21() {
super(21);
}
public static void main(String[] args) {
new Day21().printParts();
}
@Override
public Object part1() {
IntcodeComputer ic = new IntcodeComputer(21);
// !(A && B && C) && D
ic.setInput("OR A T\n" +
"AND B T\n" +
"AND C T\n" +
"NOT T T\n" + //flip T
"AND D T\n" +
"OR T J\n" +
"WALK\n");
long res;
while ((res = ic.run()) != IntcodeComputer.STOP_CODE)
if (res > 255) return res;
return 0;
}
@Override
public Object part2() {
IntcodeComputer ic = new IntcodeComputer(21);
// (((!B && H) || !A) || (!C && H)) && D
ic.setInput("NOT A J\n" +
"NOT B T\n" +
"AND H T\n" +
"OR T J\n" +
"NOT C T\n" +
"AND H T\n" +
"OR T J\n" +
"AND D J\n" +
"RUN\n");
long res;
while ((res = ic.run()) != IntcodeComputer.STOP_CODE)
if (res > 255) return res;
return 0;
}
}