Is it possible to make the following code modular, so that it works up till depth n, and returns an array of all possible combinations for used{}
?
ranges
is an nx2 array which contains the ranges for the ith loop.
used = Table[0, lb]
For[i = ranges[[1, 1]], i <= ranges[[1, 2]], i++,
used[[1]] = i;
For[j = ranges[[2, 1]], j <= ranges[[2, 2]], j++,
If[FreeQ[used, j],
used[[2]] = j;
For[k = ranges[[3, 1]], k <= ranges[[3, 2]], k++,
If[FreeQ[used, k],
used[[3]] = k;
For[l = ranges[[4, 1]], l <= ranges[[4, 2]], l++,
If[FreeQ[used, l],
used[[4]] = l;
For[m = ranges[[5, 1]], m <= ranges[[5, 2]], m++,
If[FreeQ[used, m],
used[[5]] = m;
(*operations*)
used[[5]] = 0;
];
];
used[[4]] = 0;
];
];
used[[3]] = 0;
];
];
used[[2]] = 0;
];
];
used[[1]] = 0
];
I am not able to find the proper tags, so suggestions are welcome.
used
without using all these nested loops, and preferably in a parametric fashion (taking the number of nested loops as an input, say) $\endgroup$