Re: simple question
- To: mathgroup at smc.vnet.net
- Subject: [mg68666] Re: simple question
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 16 Aug 2006 03:35:52 -0400 (EDT)
- References: <ebpkus$p27$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, ((Range[10] /. lst_ :> { lst, {}}) //. {{a_, b__}, {c___}} :> {{b}, {a, c}}) // Flatten if you wish to remove the last Flatten[] you can try (((Range[10] /. lst_ :> {lst, {}}) //. {{a_, b__}, {c___}} :> {{b}, {a, c}})) /. {{a_}, {c__}} :> {a, c} Regards Jens corrallia81 at yahoo.com wrote: > Hello, > > I know it is simple but I can't find something. > > In[1]:= lst=Range[10] > Out[1]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} > > In[2]:= Reverse[lst] > Out[2]={10, 9, 8, 7, 6, 5, 4, 3, 2, 1} > > How we can get the same result with pattern matching? > > My unsuccesful attempts include > > In[9]:=Range[10]/.{x_,y___}->{y,x} > > Out[9]={2, 3, 4, 5, 6, 7, 8, 9, 10, 1} > > In[10]:= > Range[10]//.{x_,y___}->{y,x} > >>From In[10]:= > ReplaceRepeated::"rrlim": "Exiting after \!\({1, 2, 3, 4, 5, 6, 7, 8, > 9, \ > 10}\) scanned \!\(65536\) times." > > Out[10]= > {7, 8, 9, 10, 1, 2, 3, 4, 5, 6} > > Can I add something to previous rules to work? > > Thanks for any help. >