MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Need a nice way to do this

  • To: mathgroup at
  • Subject: [mg40313] Re: Need a nice way to do this
  • From: Jens-Peer Kuska <kuska at>
  • Date: Mon, 31 Mar 2003 04:01:23 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <b63r1a$3oc$>
  • Reply-to: kuska at
  • Sender: owner-wri-mathgroup at


UnequalLeft[lst_, symbs_] := Module[{l, i},
      (i = 0; 
       l[#1] = Map[Function[{x}, If[x =!= #1, i++, i]] , lst]) &, 
    MapIndexed[l[#][[First[#2]]] &, lst]

and call it with

UnequalLeft[s, {a, b}]


Steve Gray 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.

  • Prev by Date: Opinions about the "Oneliners"
  • Next by Date: Re: Re: Need a nice way to do the "left count"
  • Previous by thread: Re: Need a nice way to do this
  • Next by thread: Re: Need a nice way to do this