Re: Need a nice way to do this

*To*: mathgroup at smc.vnet.net*Subject*: [mg40286] Re: Need a nice way to do this*From*: bobhanlon at aol.com (Bob Hanlon)*Date*: Sun, 30 Mar 2003 04:07:50 -0500 (EST)*References*: <b63r1a$3oc$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

f[s_?VectorQ] := Module[{n=0}, Fold[Append[#1,n-Count[Take[s, n++],#2]]&, {},s]]; s={a,b,b,a,a,a,b,a,b,a,a}; g={0,1,1,2,2,2,4,3,5,4,4}; f[s] == g True s=Table[{a,b,c}[[Random[Integer, {1,3}]]], {15}] {a,b,a,c,b,b,a,c,a,b,a,b,a,a,c} f[s] {0,1,1,3,3,3,4,6,5,6,6,7,7,7,12} Bob Hanlon In article <b63r1a$3oc$1 at smc.vnet.net>, Steve Gray <stevebg at adelphia.net> wrote: << Subject: Need a nice way to do this From: Steve Gray <stevebg at adelphia.net> To: mathgroup at smc.vnet.net Date: Sat, 29 Mar 2003 10:03:22 +0000 (UTC) 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. >><BR><BR>