-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
56 lines (44 loc) · 1.37 KB
/
solution.java
File metadata and controls
56 lines (44 loc) · 1.37 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.util.ArrayList;
import java.util.Scanner;
public class AoC_20 {
class Range {
long low, high;
Range(long low, long high) {
this.low = low;
this.high = high;
}
}
public void magic() {
ArrayList<Range> ranges = new ArrayList<>();
while (sc.hasNextLine()) {
String[] parts = sc.nextLine().trim().split("-");
ranges.add(new Range(
Long.parseLong(parts[0]),
Long.parseLong(parts[1])
));
}
int count = 0;
boolean first = true;
loopRanges:
for (long i = 0; i <= 4294967295l; i++) {
for (Range range : ranges) {
if (range.low <= i && i <= range.high) {
i = range.high;
continue loopRanges;
}
}
if (first) {
first = false;
System.out.println("Part One: " + i);
}
count++;
}
System.out.println("Part Two: " + count);
}
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
new AoC_20().magic();
System.out.println("Running time: " + (System.currentTimeMillis() - startTime) + "ms");
}
}