add timings
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
package src;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Day00 {
|
||||
public static void main(String[] args) {
|
||||
Instant start = Instant.now();
|
||||
part1();
|
||||
Instant middle = Instant.now();
|
||||
part2();
|
||||
Instant end = Instant.now();
|
||||
IO.println("part 1: " + Duration.between(start, middle).toMillis() + " ms");
|
||||
IO.println("part 2: " + Duration.between(middle, end).toMillis() + " ms");
|
||||
}
|
||||
|
||||
private static void part1() {
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package src;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Day01 {
|
||||
public static void main(String[] args) {
|
||||
Instant start = Instant.now();
|
||||
part1();
|
||||
Instant middle = Instant.now();
|
||||
part2();
|
||||
Instant end = Instant.now();
|
||||
IO.println("part 1: " + Duration.between(start, middle).toMillis() + " ms");
|
||||
IO.println("part 2: " + Duration.between(middle, end).toMillis() + " ms");
|
||||
}
|
||||
|
||||
private static void part1() {
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package src;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Day02 {
|
||||
public static void main(String[] args) {
|
||||
Instant start = Instant.now();
|
||||
part1();
|
||||
Instant middle = Instant.now();
|
||||
part2();
|
||||
Instant end = Instant.now();
|
||||
IO.println("part 1: " + Duration.between(start, middle).toMillis() + " ms");
|
||||
IO.println("part 2: " + Duration.between(middle, end).toMillis() + " ms");
|
||||
}
|
||||
|
||||
private static void part1() {
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
package src;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Day03 {
|
||||
public static void main(String[] args) {
|
||||
Instant start = Instant.now();
|
||||
part1();
|
||||
Instant middle = Instant.now();
|
||||
part2();
|
||||
Instant end = Instant.now();
|
||||
IO.println("part 1: " + Duration.between(start, middle).toMillis() + " ms");
|
||||
IO.println("part 2: " + Duration.between(middle, end).toMillis() + " ms");
|
||||
}
|
||||
|
||||
private static void part1() {
|
||||
@@ -48,8 +55,7 @@ public class Day03 {
|
||||
String raw = scanner.nextLine();
|
||||
List<String> bank = List.of(raw.split(""));
|
||||
// first, get the initial 12 batteries
|
||||
List<String> curr = new ArrayList<>();
|
||||
curr.addAll(bank.subList(0, 12));
|
||||
List<String> curr = new ArrayList<>(bank.subList(0, 12));
|
||||
for (int i = 12; i < bank.size(); i++) {
|
||||
curr.add(bank.get(i)); // add the next battery to the end of the list
|
||||
// find the smallest battery in the list that's ahead of a larger battery
|
||||
@@ -61,8 +67,7 @@ public class Day03 {
|
||||
}
|
||||
curr.remove(t1);
|
||||
}
|
||||
String result = curr.stream().reduce("", String::concat);
|
||||
sum += Long.parseLong(result);
|
||||
sum += Long.parseLong(String.join("", curr));
|
||||
}
|
||||
IO.println(sum);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user