MathGroup Archive 2006

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

Search the Archive

Re: List difference using patterns and substitutions.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71348] Re: List difference using patterns and substitutions.
  • From: "dkr" <dkrjeg at adelphia.net>
  • Date: Wed, 15 Nov 2006 06:44:31 -0500 (EST)
  • References: <ejc53g$6qf$1@smc.vnet.net>

Nacho,

A simple solution would be:

In[17]:=
f[a_List]:=Most[RotateLeft[a]-a];
In[18]:=
f[{1,2,3,5,5}]
Out[18]=
{1,1,2,0}

If you insist on using pattern matching, then you could try something
like:

In[19]:=
g[a_List]:=Join[a,{{}}]//.{x_,y_,z___,{v___}}:>{y,z,{v,y-x}}//Last
In[20]:=
g[{1,2,3,5,5}]
Out[20]=
{1,1,2,0}

dkr


  • Prev by Date: Re: Arithmetic Puzzle (so simple it's hard)
  • Next by Date: coercion into series
  • Previous by thread: Re: List difference using patterns and substitutions.
  • Next by thread: Re: List difference using patterns and substitutions.