-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 19-1.java
71 lines (62 loc) · 1.9 KB
/
Day 19-1.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
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.*;
class Main {
public static HashMap<String,Integer> rules = new HashMap<String,Integer>();
public static List<String> array = new ArrayList<String>();
public static void main(String[] args) {
populateArray();
System.out.println(array + "\n");
System.out.println(rules + "\n");
int followsZero = 0;
//firstStar(0);
}
public static void firstStar(int index){
boolean reachend = false;
String currVal = array.get(index);
for (int i = 0; i < currVal.length(); i++){
String charAt = currVal.substring(i, i+1);
}
}
public static boolean isNumeric(String strNum) {
if (strNum == null) {
return false;
}
try {
double d = Double.parseDouble(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public static void populateArray(){
try {
File myObj = new File("puzzle.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String nextLine = myReader.nextLine();
nextLine = nextLine.replaceAll("\"","");
if (!nextLine.isEmpty()){
if (isNumeric(nextLine.substring(0,1))){
String[] split = nextLine.split(":");
if (split[1].contains("|")){
String[] splitTwo = split[1].split("\\|");
for (String value : splitTwo){
rules.put(value,Integer.parseInt(split[0]));
}
} else {
rules.put(split[1],Integer.parseInt(split[0]));
}
}else{
array.add(nextLine);
}
}
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}