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

• To: mathgroup at smc.vnet.net
• Subject: [mg52184] Re: [mg52172] Challenge: Fastest method to convert positive integers to 1 in a long list
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sun, 14 Nov 2004 04:30:24 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

Use Sign

seq=Table[Random[Integer,10],{10^6}];

Take[seq,20]

{9,7,1,3,3,1,5,6,6,9,6,8,6,0,5,6,8,2,3,10}

Timing[newseq=1+Quotient[#,#+1,1]&@seq;Take[newseq,20]]

{0.24 Second,{1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1}}

Timing[newseq=Sign@seq;Take[newseq,20]]

{0.06 Second,{1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1}}

Bob Hanlon

>
> From: "Carl K. Woll" <carlw at u.washington.edu>
To: mathgroup at smc.vnet.net
> Date: 2004/11/13 Sat AM 04:40:26 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg52184] [mg52172] Challenge: Fastest method to convert positive integers
to 1 in a long list
>
> 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
>
>
>

• Prev by Date: Re: TraditionalForm of expressions WITHOUT evaluating.
• Next by Date: Re: TraditionalForm of expressions WITHOUT evaluating.
• Previous by thread: Re: Challenge: Fastest method to convert positive integers to 1 in a long list
• Next by thread: Matrix Dot Product