im not able to figure out the following problem. At point 1 I could either go to point 2 or point 5. From point to I could go to 3 or 4. From point 5 I could go to 6 or 7. From 7 there is only one path to 9. I would like to calculate all the full paths. Im not looking for the fastest route or anything. I need all the paths there are in a manner that I could follow them easily.
I have 2 questions:
Im not sure im using the correct way to 'store' the options (a[1]=[2,5]). Is this ok or is there a better way ?
Im not sure how to solve this. Can anyone give me a clue ? Im hoping im looking in the right direction :-)
The path:
1 ->2 ->3
->4
->5 ->6
->7 ->8 ->9
And the desired result:
1,2,3
1,2,4
1,5,6
1,5,7,8,9
My attempt at solving this in javascript
// this doesn't do what I need
var a = [];
a[1]=[2,5];
a[2]=[3,4];
a[5]=[6,7];
a[7]=[8];
a[8]=[9];
trytoloop(a,1);
function trytoloop(a,key){
if(a[key]){
for (var y in a[key]){
document.write(key);
trytoloop(a,a[key][y]);
}
} else {
document.write(key);
}
}