5
$\begingroup$

Let's begin with a simple example. Now, we have a list,

list0=Range[4];

k1 and k2 are some elements of the list0. If |k1-k2|==2, then the elements k1 and k2 can interchange their positions.(Namely, 1 and 3 can echange; 2 and 4 can exchange) With this condition, we can get a new list including 4 elements,

listnew={{1,2,3,4},{3,2,1,4},{1,4,3,2},{3,4,1,2}};

In the listnew, the no-exchange list0 is also included. And the sequence of the elements in the listnew are not important.

My problem is, if we consider,

 list0=Range[16];

and the exchange condition is,

|k1-k1|==4 Or |k1-k1|==8 Or |k1-k1|==12

How to get the listnew by using a general and simple way ?

$\endgroup$
6
$\begingroup$

This works for 16 elements too:

list0 = Range[4];

sep = 2; (* separation of exchangeable elements *)

exchangeable = 
 Select[Subsets[list0, {2}], Abs[Subtract @@ #] == sep &]
(* {{1, 3}, {2, 4}} *)

group = PermutationGroup[Cycles[{#}] & /@ exchangeable]
(* PermutationGroup[{Cycles[{{1, 3}}], Cycles[{{2, 4}}]}] *)

elements = GroupElements[group]
(* {Cycles[{}], Cycles[{{2, 4}}], Cycles[{{1, 3}}], Cycles[{{1, 3}, {2, 4}}]} *)

listnew = PermutationList[#, Length[list0]] & /@ elements
(* {{1, 2, 3, 4}, {1, 4, 3, 2}, {3, 2, 1, 4}, {3, 4, 1, 2}} *)

Be sure to add semicolons to suppress output when trying it for 16 elements.

$\endgroup$
  • $\begingroup$ Thanks. This is just what I want to get. $\endgroup$ – Orders Oct 5 '15 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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