public
Created

  • Download Gist
gistfile1.java
Java
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 28 29 30 31 32 33 34 35 36 37 38 39 40
package playground;
 
import java.util.ArrayList;
 
/**
*
*/
public class Playground {
 
public static ArrayList<ArrayList<Integer>> nextPermutation() {
ArrayList<Integer> storesPermutations = new ArrayList<>(10);
ArrayList<ArrayList<Integer>> storesLists = new ArrayList<>(10);
for (int i = 0; i < 10; i++) {
ArrayList<Integer> allValues = new ArrayList<>(10);
for (int j = 0; j < 10; j++) {
allValues.add(j + 1);
}
 
while (allValues.size() > 0) {
int storesRand = (int) (Math.random() * (allValues.size()));
int temp = (int) allValues.get(storesRand);
if (storesPermutations.size() < 10) {
storesPermutations.add(temp);
} else {
break;
}
allValues.remove(storesRand);
storesLists.add(storesPermutations);
}
}
return storesLists;
}
 
public static void main(String[] args) {
ArrayList<ArrayList<Integer>> mainList = nextPermutation();
for (int k = 0; k < 10; k++) {
System.out.println("List " + (k + 1) + ": " + (mainList.get(k)));
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.