MathGroup Archive 2006

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

Search the Archive

Re: simple question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68681] Re: [mg68643] simple question
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 16 Aug 2006 03:36:12 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

Range[10]//.{s___,x_,y_,e___}/;y>x:>
    {s,y,x,e}

{10,9,8,7,6,5,4,3,2,1}


Bob Hanlon

---- 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.
> 

--

Bob Hanlon
hanlonr at cox.net



  • Prev by Date: too many special linear matrices
  • Next by Date: Re: Solving integrals
  • Previous by thread: Re: simple question
  • Next by thread: Re: simple question