-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadventofcodeDay5Part1.java
More file actions
56 lines (50 loc) · 1.58 KB
/
Copy pathadventofcodeDay5Part1.java
File metadata and controls
56 lines (50 loc) · 1.58 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
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.lang.Math;
public class adventofcodeDay5Part1 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
File readFile = new File("/home/piyi/input.txt");
try{
Scanner fileReader = new Scanner(readFile);
int max = 0;
int seatID = 0;
while (fileReader.hasNextLine()) {
String data = fileReader.nextLine();
String[] arrOfStr = data.split("", -2);
int column = 0;
int row = 0;
for( int i=0; i < 7; i++ ){
System.out.println(arrOfStr[i]);
if( arrOfStr[i].equals("B"))
{
row = row + (int) Math.pow(2, 6-i);
System.out.println((int) Math.pow(2, 6-i));
}
}
for( int i=7; i < 10; i++ ){
if( arrOfStr[i].equals("R"))
{
column = column + (int) Math.pow(2, 9-i);
}
}
System.out.println(row);
System.out.println(column);
System.out.println("#####");
seatID = row * 8 + column;
if (seatID > max){
max = seatID;
}
}
System.out.println(max);
fileReader.close();
}
catch(Exception E){
System.out.println(E);
}
}
}