Re: Re: functional routine for {a, b, c, ...} -> {a - b, b - c, c - ...a}
- To: mathgroup at smc.vnet.net
- Subject: [mg24930] Re: [mg24907] Re: [mg24892] functional routine for {a, b, c, ...} -> {a - b, b - c, c - ...a}
- From: "Dr. Reinhard Simonovits" <Reinhard.Simonovits at kfunigraz.ac.at>
- Date: Tue, 22 Aug 2000 16:22:41 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>Dear Marteen Probably you like that kind of programming style: In[36]:= #1-#2& @@ # & /@ Partition[{a, b, c, d, e, f, g, h},2,1] Out[36]= {a-b,b-c,c-d,d-e,e-f,f-g,g-h} Partition produces {{a,b},{b,c},...} and #1-#2& generates the difference e.g. In[37]:= #1-#2& @@ {a,b} Out[37]= a-b > > > > lst = {a, b, c, d, e, f, g, h}; > > > > Table[lst[[i]] - lst[[i + 1]], {i, 1, Length[lst] - 1}] > > {a - b, b - c, c - d, d - e, e - f, f - g, g - h} > > > > ListCorrelate[{1, -1}, lst] > > {a - b, b - c, c - d, d - e, e - f, f - g, g - h} > > > > The first method is rather clumsy and the 2nd one is quite short, but not > > really obvious. > > Initally I was looking for a functional programming style routine. > > Something like: (#[[i]]-#[[i-1]])&/@lst. > > Who can tell me how to do this in a functional programming style? > > > > Thanks > > > > Maarten van der Burgt > > Leuven, Belgium > > > > > > > > ******************************************** Dr. Reinhard Simonovits Handelsakademie | Karl Franzens University Math Department | Inst. of Th. Physics Grazbachgasse 71 | Universitaetsplatz 5 A-8010 Graz, Austria Email: Reinhard.Simonovits at kfunigraz.ac.at *********************************************