function test() {
world.Note("<---begin test--->");
var h1 = new Utilities.Set([{name:"a1",value:"a1"},
{name:"a2",value:"a2"},
{name:"a3",value:"a3"}
]);
var h2 = new Utilities.Set([{name:"a1",value:"a1"},
{name:"a2",value:"a2"},
{name:"a3",value:"a3"}
]);
var h3 = new Utilities.Set([{name:"a1",value:"a1"},
{name:"a2",value:"a2"}
]);
var h4 = new Utilities.Set([{name:"a1",value:"a1"},
{name:"a2",value:"a2"},
{name:"a3",value:"a3"},
{name:"a4",value:"a4"}
]);
var hSet = new Utilities.Set([{name:"h1",value:h1},
{name:"h2",value:h2},
{name:"h3",value:h3}//,
//{name:"h4",value:h4}
]);
//how many combinations there are without repeats.
var permutations = Utilities.factorial(hSet.size);
//gets a copy of the array elements held in a set object.
//this is used as an absolute reference for wrkArray.
var path = hSet.elements.concat();
//wrkArray holds pointers to relative position.
//i.e. path ='s ["H1","H2","H3"];
//if wrkArray = [0,2,1] then
//it would make a path of: H1,H3,H2
var wrkArray = [];
//initializes wrkArray to 0,1,2...
for (var pc = 0;pc < path.length;pc++) {
wrkArray.push(pc);
}
//a display function for testing.
function testing(rAry,rPath) {
var str = "path: " + rPath[rAry[0]];
for (var tCount = 1;tCount < rPath.length;tCount++){
str += ", " + rPath[rAry[tCount]];
}
world.note(str);
}
for (var c = 0;c < permutations;c++) {
possibleCombinations(c,wrkArray,path);
if (!pathCheck(wrkArray,path)) {
testing(wrkArray,path);
world.Note ("is a path that doesn't miss");
c = permutations;
}
}
world.Note("<-----end test------>");
}
this would give me an output of:
h1,h3,h2
is a path that doesn't miss
Would be interested to know if anyone has some better ideas. |