I have a javascript application where I need to run a test of each possible combination of the numbers 0 through 6, without duplicating any number in the combination.
So: 0123456, 0123465, 0123546, 0123564 ...
(but, for example, 0123455, should not be included because 5 is duplicated)
I have done it iterativly:
function testAllCombinations(){
for(var i = 0; i < 7; i++){
for(var j = 0; j < 7; j++){
if(j == i)
continue;
for(var k = 0; k < 7; k++){
if(k == j || k == i)
continue;
for(var l = 0; l < 7; l++){
if(l == k || l == j || l == i)
continue;
for(var m = 0; m < 7; m++){
if(m == l || m == k || m == j || m == i)
continue;
for(var n = 0; n < 7; n++){
if(n == m || n == l || n == k || n == j || n == i)
continue;
for(var o = 0; o < 7; o++){
if(o == n || o == m || o == l || o == l || o == j || o == i)
continue;
runTest(i, j, k, l, m, n, o);
}
}
}
}
}
}
}
}
and it works fine, but I'd like to do it recursively, and I'm having a really hard time constructing the algorithm.
Can anyone provide me some direction?
Thanks in advance.