-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day04.java
26 lines (25 loc) · 985 Bytes
/
Day04.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.stream.Stream;
public class Day04 {
public static void main(String[] args) throws Exception {
int part1 = 0;
int part2 = 0;
try (BufferedReader br = new BufferedReader(new FileReader("inputs/day04.txt"))) {
String line;
while ((line = br.readLine()) != null) {
String[] vals = line.split("[-,]");
Integer[] sections = Stream.of(vals).map(Integer::valueOf).toArray(Integer[]::new);
int lo1 = sections[0], hi1 = sections[1], lo2 = sections[2], hi2 = sections[3];
if (lo1 <= lo2 && hi1 >= hi2 || lo2 <= lo1 && hi2 >= hi1) {
++part1;
}
if (lo2 <= hi1 && lo2 >= lo1 || lo1 <= hi2 && lo1 >= lo2) {
++part2;
}
}
}
System.out.println(part1);
System.out.println(part2);
}
}