MathGroup Archive 2004

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

Search the Archive

Re: Challenge: Fastest method to convert positive integers to 1 in a long list


On Nov 13, 2004, at 4:40 AM, Carl K. Woll wrote:

> Hi all,
>
> Inspired by the recent thread on counting runs, I have the following
> challenge. Come up with a method to convert all the positive integers 
> in a
> long sequence of nonnegative integers to 1, so that the sequence 
> consists of
> only 0s and 1s. Let the sequence be given by
>
> seq = Table[Random[Integer, 10], {10^6}];
>
> Then, one technique is
>
> newseq = 1+Quotient[#,#+1,1]&@seq;
>
> Can anyone do better?
>
> Carl Woll


This one seems a tad faster:

(newseq = Mod[#+2,#+1]&@seq;) // Timing

{0.16 Second, Null}

versus your

(newseq = 1 + Quotient[#,#+1,1]&@seq;) // Timing

{0.23 Second, Null}


-----
Selwyn Hollis
http://www.appliedsymbols.com
(edit reply-to to reply)


  • Prev by Date: Re: Challenge: Fastest method to convert positive integers to 1 in a long list
  • Next by Date: Re: Matrix Dot Product
  • Previous by thread: Re: Challenge: Fastest method to convert positive integers to 1 in a long list
  • Next by thread: Re:Re: Counting Runs