I tried thinking of an algorithm, but couldn't do it. Here is the problem:
There are 16 elements, grouped by four types (a, b, c and d). We also have four groups, A, B, C and D.
In the initial state, the four groups have four random elements each, eg.:
A: c, c, a, d
B: b, b, a, a
C: b, b, c, c
D: d, d, d, a
The order of elements in the group is significant.
There are two operations permitted:
1) rotating the elements of the group (in both directions), eg.:
c, c, a, d -> d, c, c, a
2) swapping two adjacent elements in a group with the corresponding elements in an adjacent group, considering that the first and last groups and elements are also adjacent, so.:
A: (c, c), a, d
B: (b, b), a, a
->
A: (b, b), a, d
B: (c, c), a, a
or
A: c), c, a, (d
D: d), d, d, (a
->
A: d), c, a, (a
D: c), d, d, (d
The goal of the algorithm is to place the elements into their corresponding groups (A: a, a, a, a
, etc.). The algorithm doesn't have to be optimal in terms of time and solution, but it should be reasonably fast on average (ie. no brute-force).
Can anyone help? Is this algorithm even polynomial?