I set myself a programming challenge using Java 8 lambda expressions and, well, I was unable to solve it! So I am turning here to see if anyone can figure out the solution.
The Problem Generate an array of arrays containing all permutations of integers, 0 - 4, starting with single values 0 - 4, then pairs of values 00,01,02 etc, then triples, then quadruples, as follows: Results int[][] results; result[0] = {0} result[1] = {1} result[2] = {2} result[3] = {3} result[4] = {4} result[5] = {0,0} result[6] = {0,1} result[7] = {0,2} result[8] = {0,3} result[9] = {0,4} result[10] = {1,0} result[11] = {1,1} result[12] = {1,2} result[13] = {1,3} result[14] = {1,4} ... {4,3} {4,4} {0,0,0} {0,0,1} {0,0,2} ... {4,4,4} {0,0,0,0} {0,0,0,1} ... {4,4,4,4} The constraint You must use only Java 8 lambda expressions. This might be quite easy to do with for loops, but try doing it with lambda expressions. The best I have been able to do so far is to generate all pairs: Integer[][] result = IntStream.rangeClosed(0, 4) .boxed() .flatMap(x -> IntStream.rangeClosed(0, 4).mapToObj(y -> new Integer{}{x,y })) .toArray(Integer[][]::new); If you can, write the code to generate all the required arrays. -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To unsubscribe from this group and stop receiving emails from it, send an email to javaposse+unsubscr...@googlegroups.com. To post to this group, send email to javaposse@googlegroups.com. Visit this group at http://groups.google.com/group/javaposse. For more options, visit https://groups.google.com/d/optout.