-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDay25.java
52 lines (44 loc) · 1.58 KB
/
Day25.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
package com.sbaars.adventofcode.year19.days;
import com.sbaars.adventofcode.year19.Day2019;
import com.sbaars.adventofcode.year19.intcode.IntcodeComputer;
import com.sbaars.adventofcode.year19.intcode.RetentionPolicy;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Day25 extends Day2019 {
public Day25() {
super(25);
}
public static void main(String[] args) {
new Day25().play();
}
private void play() {
IntcodeComputer ic = new IntcodeComputer(RetentionPolicy.EXIT_ON_EMPTY_INPUT, dayNumbers(","));
while (true) {
long res;
while ((res = ic.run()) != IntcodeComputer.STOP_CODE) System.out.print((char) res);
try {
ic.setInput(new BufferedReader(new InputStreamReader(System.in)).readLine() + "\n");
} catch (Exception ignored) {
}
}
}
@Override
public Object part1() {
IntcodeComputer ic = new IntcodeComputer(RetentionPolicy.EXIT_ON_EMPTY_INPUT, dayNumbers(","));
String[] inputs = new String[]{"west", "take semiconductor", "west", "take planetoid", "west", "take food ration", "west", "take fixed point", "east", "east", "south", "east", "east", "north", "east", "north"};
String numbers = "";
for (int i = 0; i <= inputs.length; i++) {
long res;
while ((res = ic.run()) != IntcodeComputer.STOP_CODE) {
if (Character.isDigit((char) res)) numbers += (char) res;
}
if (i == inputs.length) return numbers.substring(1);
ic.setInput(inputs[i] + "\n");
}
return 0;
}
@Override
public Object part2() {
return "MERRY CHRISTMAS!!";
}
}