1
$\begingroup$

I wrote this code:

n = 8;
U = RandomSample[Range[0, n-2]];
V = Table[{Sin[2π k/(n-1)], Cos[2π k/(n-1)]}, {h, 0, n-2}, {k, -h, n-2-h}];
W = V /. Thread[V[[1]] -> U];

The code does exactly what I expect. On the other hand, I would like to get W directly from U, without passing through V, for example using Mod[]. Can you help me? Thanks.

$\endgroup$
0

1 Answer 1

5
$\begingroup$

You can easily see that $W$ is just the collection of cyclic rotation of the list $U$. So try

W = Table[RotateRight[U, i], {i, 0, n - 2}]
$\endgroup$
1
  • 4
    $\begingroup$ Or slightly shorter, W = NestList[RotateRight, U, n - 2] $\endgroup$ Commented Feb 16 at 18:59