MathGroup Archive 2006

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

Search the Archive

Re: Need pure function to opeate on integer lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68119] Re: Need pure function to opeate on integer lists
  • From: Peter Pein <petsie at dordos.net>
  • Date: Mon, 24 Jul 2006 05:52:27 -0400 (EDT)
  • References: <ea1nf3$pja$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Terry schrieb:
> Hi All,
>    Suppose I have a list of integers, such as
> 
> listA = {1,2,5,6,7,12,13,15,16,17,18,22,23,24}
> 
> how do I construct a pure function that will difference successive 
> integer elements to produce
> 
> {1-24,2-1,5-2,6-5,7-6,12-7,13-12,15-13,16-15,17-16,18-17,22-18,23-22,24-23}
> 
> Thanks in advance
> ......Terry
> 
> 
> 
> 
Hi Terry,

something like

In[1]:=
cyclicDifference=-Subtract@@@Partition[Prepend[#,Last[#]],2,1]&;
cyclicDifference@{1,2,5,6,7,12,13,15,16,17,18,22,23,24}
Out[2]=
{-23,1,3,1,1,5,1,2,1,1,1,4,1,1}

?

Peter


  • Prev by Date: Re: Need pure function to opeate on integer lists
  • Next by Date: Re: Need pure function to opeate on integer lists
  • Previous by thread: Re: Need pure function to opeate on integer lists
  • Next by thread: Re: Need pure function to opeate on integer lists