This is a response to this brute-force version this brute-force version where the algorithm was not intended for review.
This is a response to this brute-force version where the algorithm was not intended for review.
This is a response to this brute-force version where the algorithm was not intended for review.
private static int[][] getTriangle(Path source) throws IOException {
try(Stream<String> lines = Files.lines(source)) {
return lines.map(line -> line.String::trim())
.filter(line -> !line.isEmpty())
.map(level -> parseLevel(level))
.toArray(sz -> new int[sz][]);
}
}
private static int[] parseLevel(String level) {
return Stream.of(level.trim().split("\\s+"))
.mapToInt(Integer::parseInt)
.toArray();
}
private static int[][] getTriangle(Path source) throws IOException {
try(Stream<String> lines = Files.lines(source)) {
return lines.map(line -> line.trim())
.filter(line -> !line.isEmpty())
.map(level -> parseLevel(level))
.toArray(sz -> new int[sz][]);
}
}
private static int[] parseLevel(String level) {
return Stream.of(level.trim().split("\\s+"))
.mapToInt(Integer::parseInt)
.toArray();
}
private static int[][] getTriangle(Path source) throws IOException {
try(Stream<String> lines = Files.lines(source)) {
return lines.map(String::trim)
.filter(line -> !line.isEmpty())
.map(level -> parseLevel(level))
.toArray(sz -> new int[sz][]);
}
}
private static int[] parseLevel(String level) {
return Stream.of(level.split("\\s+"))
.mapToInt(Integer::parseInt)
.toArray();
}
I decided to use some Java 8-based idioms to parse and process the triangle. This is where I hope to get some focus for the review as well, whether there are better Java-8 ways to do this.
I decided to use some Java 8-based idioms to parse and process the triangle.
I decided to use some Java 8-based idioms to parse and process the triangle. This is where I hope to get some focus for the review as well, whether there are better Java-8 ways to do this.