Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
|
a30eef69c6 |
2 changed files with 93 additions and 1 deletions
84
src/Day05.java
Normal file
84
src/Day05.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Day05 extends Input{
|
||||||
|
private int[][] sample_rules;
|
||||||
|
private ArrayList<int[]> sample_pages;
|
||||||
|
|
||||||
|
private int[][] rules;
|
||||||
|
private ArrayList<int[]> pages;
|
||||||
|
|
||||||
|
|
||||||
|
public Day05() throws IOException {
|
||||||
|
// Initialise the input object
|
||||||
|
Input input = new Input();
|
||||||
|
input.init("in/Day05");
|
||||||
|
|
||||||
|
//Extract the 2 parts of the input
|
||||||
|
ArrayList<String> sample_rules_str = new ArrayList<>();
|
||||||
|
ArrayList<String> sample_pages_str = new ArrayList<>();
|
||||||
|
boolean rules = true;
|
||||||
|
for(String s : input.getSample_input()){
|
||||||
|
if(s.isEmpty()){
|
||||||
|
rules = false;
|
||||||
|
} else {
|
||||||
|
if(rules){
|
||||||
|
sample_rules_str.add(s);
|
||||||
|
} else {
|
||||||
|
sample_pages_str.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<String> rules_str = new ArrayList<>();
|
||||||
|
ArrayList<String> pages_str = new ArrayList<>();
|
||||||
|
rules = true;
|
||||||
|
for(String s : input.getSample_input()){
|
||||||
|
if(s.isEmpty()){
|
||||||
|
rules = false;
|
||||||
|
} else {
|
||||||
|
if(rules){
|
||||||
|
rules_str.add(s);
|
||||||
|
} else {
|
||||||
|
pages_str.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the rules easier to parse
|
||||||
|
this.sample_rules = new int[sample_rules_str.size()][2];
|
||||||
|
for (int i = 0; i < sample_rules_str.size(); i++) {
|
||||||
|
String[] split = sample_rules_str.get(i).split("\\|");
|
||||||
|
int[] temp_rule = {Integer.parseInt(split[0]), Integer.parseInt(split[1])};
|
||||||
|
this.sample_rules[i] = temp_rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rules = new int[rules_str.size()][2];
|
||||||
|
for (int i = 0; i < rules_str.size(); i++) {
|
||||||
|
String[] split = rules_str.get(i).split("\\|");
|
||||||
|
int[] temp_rule = {Integer.parseInt(split[0]), Integer.parseInt(split[1])};
|
||||||
|
this.rules[i] = temp_rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the pages easier to parse
|
||||||
|
this.sample_pages = new ArrayList<>();
|
||||||
|
for(String s : sample_pages_str){
|
||||||
|
String[] split = s.split(",");
|
||||||
|
int[] pages = new int[split.length];
|
||||||
|
for (int i = 0; i < split.length; i++) {
|
||||||
|
pages[i] = Integer.parseInt(split[i]);
|
||||||
|
}
|
||||||
|
this.sample_pages.add(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pages = new ArrayList<>();
|
||||||
|
for(String s : pages_str){
|
||||||
|
String[] split = s.split(",");
|
||||||
|
int[] pages = new int[split.length];
|
||||||
|
for (int i = 0; i < split.length; i++) {
|
||||||
|
pages[i] = Integer.parseInt(split[i]);
|
||||||
|
}
|
||||||
|
this.pages.add(pages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,6 +82,14 @@ public class Main {
|
||||||
System.out.printf("Day 3 part 1 (sample): %d (%dms)\n", day03_p1_sample, day03_p1_sample_t);
|
System.out.printf("Day 3 part 1 (sample): %d (%dms)\n", day03_p1_sample, day03_p1_sample_t);
|
||||||
System.out.printf("Day 3 part 1 : %d (%dms)\n", day03_p1, day03_p1_t);
|
System.out.printf("Day 3 part 1 : %d (%dms)\n", day03_p1, day03_p1_t);
|
||||||
System.out.printf("Day 3 part 2 (sample): %d (%dms)\n", day03_p2_sample, day03_p2_sample_t);
|
System.out.printf("Day 3 part 2 (sample): %d (%dms)\n", day03_p2_sample, day03_p2_sample_t);
|
||||||
System.out.printf("Day 3 part 2: %d (%dms)", day03_p2, day03_p2_t);
|
System.out.printf("Day 3 part 2: %d (%dms)\n", day03_p2, day03_p2_t);
|
||||||
|
|
||||||
|
System.out.println("\nDay 5:");
|
||||||
|
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
Day05 day05 = new Day05();
|
||||||
|
long day05_init = System.currentTimeMillis() - start;
|
||||||
|
|
||||||
|
System.out.printf("Day 5 init took %dms", day05_init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue