Re: Need a nice way to do this

*To*: mathgroup at smc.vnet.net*Subject*: [mg40296] Re: [mg40279] Need a nice way to do this*From*: Dr Bob <majort at cox-internet.com>*Date*: Sun, 30 Mar 2003 04:09:47 -0500 (EST)*References*: <200303291019.FAA04099@smc.vnet.net>*Reply-to*: majort at cox-internet.com*Sender*: owner-wri-mathgroup at wolfram.com

leftCount[s_List] := Block[{count}, count[any_] := 0; Range@Length@s - Rest@FoldList[++count[#2] &, s, s]] leftCount[s] {0, 1, 1, 2, 2, 2, 4, 3, 5, 4, 4} or leftCount[s_List] := Block[{count, n = 0}, count[any_] := 0; Rest@FoldList[++n - (++count[#2]) &, s, s]] leftCount[s] {0, 1, 1, 2, 2, 2, 4, 3, 5, 4, 4} Bobby On Sat, 29 Mar 2003 05:19:39 -0500 (EST), Steve Gray <stevebg at adelphia.net> wrote: > Given a list consisting of only two distinct values, such as > s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length > g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position > 1<=p<=Length[s], look at list s and set g[[p]] to the number of > elements in s to the left of p which are not equal to s[[p]]. > In a more general version, which I do not need now, s would > not be restricted to only two distinct values. > > Thank you for any ideas, including other applications where > this particular calculation is used. The current application is an > unusual conjecture in geometry. > > > -- majort at cox-internet.com Bobby R. Treat

**References**:**Need a nice way to do this***From:*Steve Gray <stevebg@adelphia.net>