Re: number of switches
- To: mathgroup at smc.vnet.net
- Subject: [mg47548] Re: number of switches
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Thu, 15 Apr 2004 05:02:14 -0400 (EDT)
- Organization: The University of Western Australia
- References: <c5j6vd$qqo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <c5j6vd$qqo$1 at smc.vnet.net>, "fake" <fake at fake.it> wrote: > Consider the lists {1,1,0,1} and {1,1,0,0},{1,0,1,0,1}. > The first sequence (1101) switches 2 times (#2digit~#3digit, > #3digit~#4digit}, the second (1100) 1 time, the third 10101 4 times. > > I have the following problem. > Consider a list of binary digits. Which is the easiest way to count the > number of switches of the list (using Mathematica commands)? Use Split: Switches[l_List] := Length[Split[l]] - 1 This works with arbitrary lists of numbers or symbols. Cheers, Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul at physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul