Re: number of switches
- To: mathgroup at smc.vnet.net
- Subject: [mg47538] Re: number of switches
- From: Jon Harrop <jdh30 at cam.ac.uk>
- Date: Thu, 15 Apr 2004 03:40:40 -0400 (EDT)
- Organization: University of Cambridge
- References: <c5j6vd$qqo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
fake 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)? Does this do it? f[{}] := 0 f[l_] := Length@Split@l - 1 I get: In := f[{1,1,0,1}] Out := 2 In := f[{1,1,0,0}] Out := 1 In := f[{1,0,1,0,1}] Out := 4 As well as f[{}]=0. :) Cheers, Jon.