Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Need a nice way to do this

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40292] Re: Need a nice way to do this
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Sun, 30 Mar 2003 04:08:25 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 3/29/03 at 5:19 AM, stevebg at adelphia.net (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]]. 

Here is something that will do the trick

MapThread[(Length[Take[s, #2]] - Length[Position[
            Take[s, #2], #1]]) &, {s, Range[Length[s]]}]


  • Prev by Date: Re: Fit with lists instead of functions
  • Next by Date: Re: Need a nice way to do this
  • Previous by thread: Re: Need a nice way to do this
  • Next by thread: Re: Need a nice way to do this