Re: List difference using patterns and substitutions.
- To: mathgroup at smc.vnet.net
- Subject: [mg71332] Re: [mg71306] List difference using patterns and substitutions.
- From: János <janos.lobb at yale.edu>
- Date: Wed, 15 Nov 2006 06:43:34 -0500 (EST)
- References: <200611141006.FAA06710@smc.vnet.net>
On Nov 14, 2006, at 5:06 AM, Nacho wrote: > Hello. > > I'm trying to figure how can I build a difference list from another > using only patterns and rule substitutions. > > The idea is to get from a list, another, one element shorter, where > each value is the substraction of two consecutive elements in the > original list, that is, from {1,2,3,5,5} get {1,1,2,0}. > > I've been thinking about it for a while, and I know several methods > using a more traditional programming style (with For, for example), > but > I have no idea if it is possible to make it simple and fast with rule > substitutions. > > Any idea? > > Thanks in advance. I am a mule when it comes to rules, but here is a newbie approach without For. In[1]:= lst = {1, 2, 3, 5, 5}; In[2]:= (#1[[2]] - #1[[1]] & ) /@ Partition[lst, 2, 1] Out[2]= {1, 1, 2, 0} János ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice)
- References:
- List difference using patterns and substitutions.
- From: "Nacho" <ncc1701zzz@gmail.com>
- List difference using patterns and substitutions.