MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Permutations


My solution :

In[1]:=swap[oldList_List, noSwap_List]:=
    Module[{newList = oldList,sw},
      Scan[(newList[[#]] = {newList[[#]]})&, noSwap];
      sw[lis_List] := lis /. {a___,b_ /; AtomQ[b],
	c_ /; AtomQ[c],d___} -> {a,{c,b},d};
      Nest[sw,newList,(Length[newList]-Length[noSwap])/2]//
	Flatten
      ];

In[2]:=swap[{a,b,c,d,e,f},{1,4}]

Out[2]={a,c,b,d,f,e}

In[3]:=swap[{a,b,c,d,e,f},{}]

Out[3]={b,a,d,c,f,e}


hth

V.Astanoff


  • Prev by Date: Stationarity testing of data
  • Next by Date: Problem with the Hannan Rissanen procedure
  • Previous by thread: Permutations
  • Next by thread: Re: Permutations