MathGroup Archive 2001

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

Search the Archive

Re: Uniquely Subtracting Elements in a Flat List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29214] Re: Uniquely Subtracting Elements in a Flat List
  • From: Al Kaufman <nutronstar at rickadee.net>
  • Date: Mon, 4 Jun 2001 05:30:49 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>  Alan <kd7cyb at mac.com> writes:
>
>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}.


Use Partion and Map:
In[1]:=
lst = {a,b,c,d};
res = Map[(#[[1]]-#[[2]])&, Partition[lst,2,,1]];
res

Out[1]:=
{a-b,b-c,c-d)
-- 
**************************************
*                                    *
*  Alfred Kaufman                    *
*  802 Summerset Dr                  *
*  Rio Vista,  Ca  94571             *
*  Phone:  707-374-4976              *
*  E-mail:  nutronstar at rickadee.net  *
*                                    *
*  "Reality happens a lot."          *
*                                    *
**************************************


  • Prev by Date: Re: OOP in Mathematica
  • Next by Date: Re: Notebook to PDF Windows
  • Previous by thread: Re: Uniquely Subtracting Elements in a Flat List
  • Next by thread: Line numbers