-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAdventOfCode09.java
More file actions
27 lines (24 loc) · 807 Bytes
/
AdventOfCode09.java
File metadata and controls
27 lines (24 loc) · 807 Bytes
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
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import static java.util.stream.IntStream.range;
public class AdventOfCode09 {
static int analysisOasisAndReportSum(String input) {
return input.lines()
.map(line -> Arrays.stream(line.split(" ")).map(Integer::parseInt).toList())
.mapToInt(history -> Stream.iterate(history,
h -> !h.stream().allMatch(v -> v == 0),
h -> range(1, h.size()).mapToObj(i -> h.get(i) - h.get(i - 1)).toList())
.mapToInt(List::getLast)
.sum())
.sum();
}
public static void main(String[] args) {
var input = """
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
""";
System.out.println(analysisOasisAndReportSum(input));
}
}