I want to make a permutation matrix using a dynamic variable (days).
My current code has 3 loops (for 3 days), and if I wanted to add another day or delete one day, I would have to add/delete one complete for-loop.
public static ArrayList<ArrayList<Integer>> computePermutations(int stops, int days) {
int maxPerDay = stops - (days - 1);
ArrayList<ArrayList<Integer>> permutationMatrix = new ArrayList<ArrayList<Integer>>();
for (int m = 1; m <= maxPerDay; m++) {
for (int n = 1; n <= maxPerDay; n++) {
for (int o = 1; o <= maxPerDay; o++) {
if (m + n + o == stops) {
ArrayList<Integer> possibleSolution = new ArrayList<Integer>(Arrays.asList(m, n, o));
permutationMatrix.add(possibleSolution);
}
}
}
}
return permutationMatrix;
}
I also need to update the line: ArrayList<Integer> possibleSolution = new ArrayList<Integer>(Arrays.asList(m, n, o));, so the parameters (m, n, o) change depending on the amount of days.