0
0
Fork 0
paul
paul 5 years ago
parent 8a47719e2b
commit 41d4916360

@ -15,14 +15,19 @@ public class Board {
.map(this::row); .map(this::row);
} }
Stream<String> row(int row) { public Stream<Stream<String>> columns() {
return IntStream.range(0, 9).boxed() return IntStream.range(0, 9).boxed()
.map(column -> digit(row, column)); .map(this::column);
} }
public Stream<Stream<String>> columns() { public Stream<Stream<String>> squares() {
return IntStream.range(0, 3).boxed()
.flatMap(this::squares);
}
Stream<String> row(int row) {
return IntStream.range(0, 9).boxed() return IntStream.range(0, 9).boxed()
.map(this::column); .map(column -> digit(row, column));
} }
Stream<String> column(int column) { Stream<String> column(int column) {
@ -30,17 +35,12 @@ public class Board {
.map(row -> digit(row, column)); .map(row -> digit(row, column));
} }
Stream<Stream<String>> squares() { Stream<Stream<String>> squares(int squareRow) {
return IntStream.range(0, 3).boxed()
.flatMap(this::squares);
}
private Stream<Stream<String>> squares(int squareRow) {
return IntStream.range(0, 3).boxed() return IntStream.range(0, 3).boxed()
.map(squareColumn -> square(squareRow, squareColumn)); .map(squareColumn -> square(squareRow, squareColumn));
} }
private Stream<String> square(int squareRow, int squareColumn) { Stream<String> square(int squareRow, int squareColumn) {
return IntStream.range(squareRow*3, squareRow*3+3).boxed() return IntStream.range(squareRow*3, squareRow*3+3).boxed()
.flatMap(row -> squareDigitsInRow(row, squareColumn)); .flatMap(row -> squareDigitsInRow(row, squareColumn));
} }

Loading…
Cancel
Save