5
$\begingroup$

I can't seem to find a function that will input x and output y. For my application, each of the numbers 1,2,3,4 represent a list, and the matrix is much larger.

x=[{1,2,3,4}]

y=[{{1,2,3,4},
{2,3,4,1},
{3,4,1,2},
{4,1,2,3}}]

$\endgroup$
10
$\begingroup$

Square brackets are only used for functions

x = Range[4]

(* {1, 2, 3, 4} *)

y = NestList[RotateLeft, x, Length[x] - 1]

(* {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}} *)

If the extra brackets are intended

x = {Range[4]}

(* {{1, 2, 3, 4}} *)

y = {NestList[RotateLeft, x[[1]], Length[x[[1]]] - 1]}

(* {{{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}} *)
$\endgroup$
9
$\begingroup$
Permute[Range[4], CyclicGroup[4]]
 {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}

You can also use RotateLeft:

RotateLeft[Range[4], #] & /@ Range[0, 3]
{{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}
$\endgroup$
1
  • 2
    $\begingroup$ CyclicGroup is what I needed. I'm planning on using a sequence of RGBColor in Colorize, so this works for me: tab = Permute[Tuples[{0, .5, 1}, 3], CyclicGroup[27]] $\endgroup$
    – Youvan
    Mar 14 '21 at 16:37
8
$\begingroup$
x = Range[4];
Partition[x, Length[x], 1, 1]

{{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.