-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay05A.java
58 lines (48 loc) · 1.89 KB
/
Day05A.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
package advent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Day05A {
public static void main(String[] args) throws IOException {
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Paste the input:");
final ArrayList<String> boardingPasses = new ArrayList<>();
String readLine;
do {
readLine = bufferedReader.readLine();
if (readLine != null && !readLine.isEmpty()) {
boardingPasses.add(readLine.trim());
} else {
break;
}
} while (true);
bufferedReader.close();
System.out.println("got " + boardingPasses.size() + " BoardingPasses");
int highestSeatId = 0;
for (final String boardingPass : boardingPasses) {
int row = 0;
int col = 0;
for (int i = 0; i < boardingPass.length(); i++) {
// System.out.println(boardingPass.charAt(i) + " i: " + i);
if (i < boardingPass.length() - 3) {
if (boardingPass.charAt(i) == 'B') {
row += 1 << (6 - i);
// System.out.println("row: " + row);
}
} else {
if (boardingPass.charAt(i) == 'R') {
col += 1 << (9 - i);
// System.out.println("col: " + col);
}
}
}
System.out.println("BoardingPass: " + boardingPass + " row: " + row + "col: " + col);
final int newSeatId = (row * 8) + col;
if (highestSeatId < newSeatId) {
highestSeatId = newSeatId;
}
}
System.out.println("Highest BoardingPass: " + highestSeatId);
}
}