Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

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.

Tweeted twitter.com/#!/StackCodeReview/status/608510527996858368
fix small / bad java-8isms
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419
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();
}
add specific request
Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419

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.

Source Link
rolfl
  • 98.1k
  • 17
  • 219
  • 419
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /