An array of int
(between 0 and 30) has N rows and 4 columns.
It has a head
and a tail
, a start and an end.
All the rows but two have to be permutated between the head
and the tail
. The rows identified as the head
and the tail
can be moved, but the distance between the two must, from top to bottom, remain the same.
Example:
In this picture, the sequence { 2, 4, 7, 9 }
is the head
, { 7, 1, 9, 4 }
is the tail
. Thus, only the elements between these two can be shuffled row by row (not column by column).
(It must be noted that "Row#" refers to the row which contains the respective sequences, not the absolute rows from our perspective. Then "Row3" in this picture is situated at the second row).
Theoretically, if I am right, there are 3! possible permutations.
But these elements can not be randomly shuffled. A specific configuration is sought.
First contraint: Each int of the second column (here: ColB) must be identical to the int situated at x mod N
rows below it in the first column (ColA). (x
is arbitrary: we know that there is a solution for a given x
).
Second constraint: Each int of the third column (ColC) must be identical to the int
just below it, mod N (then, NC = 1D
), in the fourth column (ColD).
An example of good configuration (x = 3
here):
Take the number 4, row1, colB. It is identical to the number situated at ((row where is 4)+3) % 5
, colA (in blue). And this is also the case for all numbers of ColB.
Take the number 7, row1, colC. It is identical to the number situated at ((row where is 7)+1) % 5
, colD (in yellow).
This is a good configuration too (x = 3
too):
Head
and tail
have been moved, but the distance from top to bottom (we start from head
of course) between the two remains the same.
Take the number 2, row3 (the fourth row then), colB. It is identical to the number situated at ((row where is 2)+3) % 5
= second row, colA.
As you see, it is very simple, trivial to solve in this situation.
Now imagine that N = 300. 300-2 rows must be permutated in order to meet the constraints. Then 298! permutations possible. It seems unsolvable.
Do you know if an algorithm can help to solve this problem with N = 300 rows with repetitive int
s in a reasonable time (that is, < age of the Universe)?
Thanks!