Re: Uniquely Subtracting Elements in a Flat List

• To: mathgroup at smc.vnet.net
• Subject: [mg29203] Re: [mg29182] Uniquely Subtracting Elements in a Flat List
• From: David Withoff <withoff at wolfram.com>
• Date: Mon, 4 Jun 2001 05:30:37 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```> I need help taking a flat list, such as {a,b,c,d} and generating another
> list by successively subtracting a-b, b-c, c-d, so that the resulting
> list would be {a-b,b-c,c-d}.
>
> Thanks,
> Alan

One interesting way to do this is to use ListConvolve:

In[1]:= flatlist={a,b,c,d}

Out[1]= {a,b,c,d}

In[2]:= ListConvolve[{-1,1},flatlist]

Out[2]= {a-b,b-c,c-d}

There are lots of other solutions, though...

In[3]:= Rest[RotateRight[flatlist]-flatlist]

Out[3]= {a-b,b-c,c-d}

In[4]:= Table[flatlist[[k]]-flatlist[[k+1]],{k,Length[flatlist]-1}]

Out[4]= {a-b,b-c,c-d}

etc. etc.

```

• Prev by Date: Re: multiplyin a symbol by 0
• Next by Date: Re: Repeating decimals
• Previous by thread: RE: Uniquely Subtracting Elements in a Flat List
• Next by thread: Re: Uniquely Subtracting Elements in a Flat List