I want to check every possible combination of Items in a given number of arrays.
So if I have 3 arrays it would be like this:
Array1 | Item1, Item2, Item3
Array2 | Item1, Item2, Item3
Array3 | Item1, Item2, Item3
To do that I want to shift the Item arrays one by one but only when the Items of the previous position do a full rotation.
So when the Items of Array1 do a full rotation then the Items from Array2 can rotate.
How can I do this for any given number of arrays, while the item list is always the same?
Yah I got nested structs, and I get that I can pop the stack to rotate it. What I’m having trouble with is actually triggering the rotation of the next array.
Right now I even abandoned the idea of rotating the sub array itself and I’m using incidences instead. It’s easier to check if the index is the same length as the sub array to confirm if it did a full resolution, instead of keeping track of the sub array items.
If you know how I could cleanly rotate the next array when the current does a full resolution please share.
You can’t do it with a foreach loop. I only showed that to demonstrate the structure…
Each array can rotate the same number of times as elements it contains. You’ll need to have an array ( yes another ) of the ‘processing indexes’. When the last index reaches the length or the last array, you’re done.
I’ll try and come up with an example.
BTW: why are you doing this? There may be an easier way of achieving your goals…
Totally untested, but something like this will work. It’s more of a piece of concept art at the moment.
This loop basically increments the array of indexes. If the index goes off the end of an array, set it back to zero. If we just set the index of the last array back to zero, we’re done…