How to shift arrays in a carousel.

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?

1 Like

Do you actually need to rotate the arrays, or just read them in order?

Just shift them by one.

Array1 | Item1, Item2, Item3
Array1 | Item3, Item1, Item2
Array1 | Item2, Item3, Item1
Array1 | Item1, Item2, Item3

This is deceptively hard, since I’m trying to do it with any number of arrays and I’m also trying to avoid recursive.

Not so easy in blueprint, but I’d go for an array of structures, where each structure is just another array.

So

and

image

You can rotate easily with

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…

I’m trying to test every possible combination of actor and make groups with them.

Array | Item
The array is a position that I want the actor to stand at
The item is the actor

I want to see if the current number of positions can the fulfilled by a given number of actors.

So you can have a main loop like this

The increment function is

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…

2 Likes

Thank you I’m going to study it for a bit

1 Like

( I just updated the code - above, several times :slight_smile: )…

I managed to get closer to my objective thanks to you :ok_hand:

1 Like

Great :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.