Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52174] Re: [mg52172] Challenge: Fastest method to convert positive integers to 1 in a long list
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 14 Nov 2004 04:30:10 -0500 (EST)
  • References: <200411130940.EAA01037@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 13 Nov 2004, at 18:40, 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 seems to be very much faster:

newseq = Sign[seq];



Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/


  • 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: Challenge: Fastest method to convert positive integers to 1 in a long list
  • Next by thread: Re: Challenge: Fastest method to convert positive integers to 1 in a long list