Re: Challenge: Fastest method to convert positive integers to 1 in a long list
- To: mathgroup at smc.vnet.net
- Subject: [mg52187] Re: Challenge: Fastest method to convert positive integers to 1 in a long list
- From: bghiggins at ucdavis.edu (Brian Higgins)
- Date: Sun, 14 Nov 2004 04:30:31 -0500 (EST)
- References: <cn4m4e$19p$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
This is the best I could to:
seq = Table[Random[Integer, 10], {10^6}];
newseq = 1+Quotient[#,#+1,1]&@seq;//Timing
{0.16 Second,Null}
newseq2 =(If[#>0,1,0]&)/@seq;//Timing
{0.5 Second,Null}
Brian
"Carl K. Woll" <carlw at u.washington.edu> wrote in message news:<cn4m4e$19p$1 at smc.vnet.net>...
> 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