-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHolidayCode10.java
More file actions
81 lines (52 loc) · 2.07 KB
/
HolidayCode10.java
File metadata and controls
81 lines (52 loc) · 2.07 KB
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
81
import java.util.ArrayList;
import java.io.*;
public class HolidayCode10 {
public static void main(String[] args){
try{
File file = new File("bots.txt");
FileReader fileReader = new FileReader(file);
BufferedReader input = new BufferedReader(fileReader);
String line;
ArrayList<Integer> values = new ArrayList<Integer>();
for(int i = 0; i < 300; i++){
values.add(0);
}
while((line = input.readLine()) != null){
String[] parts = line.split(" ");
if(parts[0].equals("value")){
int value = Integer.parseInt(parts[1]);
int bot = Integer.parseInt(parts[5]);
values.set(value, bot);
} else {
//high-low bot thing
int bot = Integer.parseInt(parts[1]);
if(values.contains(bot)){
//Valid command. 5 and 10 can be output or bot
int lowIndex = values.indexOf(bot);
int highIndex = values.lastIndexOf(bot);
if(parts[5].equals("output")){
//Discard low value - goes back to 0 in value array
values.set(lowIndex, 0);
} else {
int recipient = Integer.parseInt(parts[6]);
values.set(lowIndex, recipient);
}
if(parts[10].equals("output")){
//Discard high value - goes back to 0 in value array
values.set(highIndex, 0);
} else {
int recipient = Integer.parseInt(parts[11]);
values.set(highIndex, recipient);
}
}
}
if(values.get(61) == values.get(17) && values.get(17) != 0){
System.out.println(values.get(61));
//break;
}
}
} catch (IOException error) { //Need this for using buffered readers
error.printStackTrace();
}
}
}