RE: number of switches
- To: mathgroup at smc.vnet.net
- Subject: [mg47527] RE: [mg47479] number of switches
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Thu, 15 Apr 2004 03:39:48 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: fake [mailto:fake at fake.it] To: mathgroup at smc.vnet.net >Sent: Wednesday, April 14, 2004 1:16 PM >To: mathgroup at smc.vnet.net >Subject: [mg47527] [mg47479] number of switches > > >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)? > In[1]:= tt = Table[Random[Integer], {30}] Out[1]= {0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, \ 1, 0, 1, 1, 0} In[3]:= Length[Split[tt]] - 1 Out[3]= 16 In[10]:= Plus @@ Abs /@ Subtract @@@ Partition[tt, 2, 1] Out[10]= 16 In[68]:= (t = FromDigits[tt], 2]; DigitCount[BitXor[Floor[t/2], t], 2, 1] - First[tt]) Out[68]= 16 -- Hartmut Wolf