Re: working with lists
- To: mathgroup at smc.vnet.net
- Subject: [mg113213] Re: working with lists
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Tue, 19 Oct 2010 05:54:37 -0400 (EDT)
On 10/18/10 at 5:47 AM, sam.takoy at yahoo.com (Sam Takoy) wrote: >I'm not very good at working with lists. May I ask for someone to >work out an example which has several elements of what I need to do. >What's the best way to write a function f[list] that goes through >each element of the lest, doubles each element divisible by three >and reduces each of the following elements by 1. That is >f[{ 1 2 3 5 7}] is { 1 2 6 4 12 } From your description above, I would expect the output to be {1,2,6,4,6} not {1,2,6,4,12} If I have this correct then the following does the trick. In[2]:= {1, 2, 3, 5, 7} /. {a__, b_?(Mod[#, 3] == 0 &), c__} :> {a, 2 b, Sequence @@ ({c} - 1)} Out[2]= {1,2,6,4,6}