MathGroup Archive 2006

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

Search the Archive

Re: Permutations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65543] Re: Permutations
  • From: "Valeri Astanoff" <astanoff at yahoo.fr>
  • Date: Fri, 7 Apr 2006 06:14:20 -0400 (EDT)
  • References: <e12s2k$j79$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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