Imagine six squares touching in two rows (3x2) layout. Now let’s say I call the first square “0”, the second “1”, third “2” and so on going left to right, then onto the second row like so:
0 1 2
3 4 5
Here’s the puzzle: How many different ways can you move around this configuration without going back to the same square, and what are those configurations of numbers?
If I start at 0, I can move to 1,3 or 4.
If I start at 1, I can move to 0,2,3,4,5
If I start at 2, I can move to 1,4,5
Here are some of the possibilities if I start from 0, the top-left square:
0143
01452
01425
015243
01542
01543
03124
03125
03145
03142
03152
03154
… and many more… 34 total if I start at 0, I believe.
I am trying to have an array store all the possible ways to go around a 3x2, grid, but would like to expand it to a 3x3, 4x4 or any other configuration of squares. My code right now doesn’t do anything really, because I’m not exactly sure how to go about solving this.
// These are the values where you can move to in a grid of 3x2. Example,
// starting at 0, you can go to either 1,3 or 4.
values = new Array(0, 1, 2, 3, 4, 5);
trace("length of values is:"+values.length);
possibilities = new Array([1, 3, 4], [0, 2, 3, 4, 5], [1, 4, 5], [0, 1, 4], [0, 1, 2, 3, 5], [1, 2, 4]);
//declaring new array, "sizes". I store the length of the sub sections in this array.
sizes = new Array();
for (var i = 0; i<possibilities.length; i++) {
sizes* = possibilities*.length;
}
trace(sizes);//output is 3,5,3,3,5,3
solutions1 = new Array();
counter = 0;
for (var j = 0; j<values.length; j++) {
//solutions2[j] = new Array(values.length);
for (var i = 0; i<sizes[j]; i++) {
trace("j is:"+j);
trace("i is:"+i);
trace("counter is:"+counter);
//trace([j]+" "+*);
trace("solutions are:"+" "+values[j]+","+possibilities[j]*);
solutions1[counter] = values[j]+"+"+possibilities[j]*;
//increase the counter for storing values in solutions 1 array
counter = counter+1;
//trace(solutions[j][counter]);
}
}
trace("solutions array1 is:"+solutions1);
trace("End");
The code above will take care of the first move on the squares. Grrrr!
Thanks for helping me out, I’m really lost.