MathGroup Archive 2006

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

Search the Archive

Re: finding the position of a pattern in list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64698] Re: finding the position of a pattern in list
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Tue, 28 Feb 2006 01:49:29 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <dtjjcv$de7$1@smc.vnet.net> <dtm5j1$hf3$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <dtm5j1$hf3$1 at smc.vnet.net>, dh <dh at metrohm.ch> wrote:

> a simple solution would be to subtract adjacent elemnts and then search 
> for +1.
> E.g.:
> 
> d = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0};
> t = Drop[d, 1] - Drop[d, -1]
> Position[t, 1] // Flatten

A slight improvement is

  d = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0};
  Position[ListConvolve[{1, -1}, d], 1] // Flatten

This is faster than solutions using Partition.

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: solid of revolution
  • Next by Date: Re: Limit
  • Previous by thread: Re: finding the position of a pattern in list
  • Next by thread: Multivariable Limits