MathGroup Archive 2007

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

Search the Archive

Re: fastest way to add up a billion numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73930] Re: [mg73880] fastest way to add up a billion numbers
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Sat, 3 Mar 2007 01:07:31 -0500 (EST)
  • References: <200703021141.GAA04040@smc.vnet.net>

On Mar 2, 2007, at 6:41 AM, Raj wrote:

> hi!
>
> Could somebody tell me what would be the fastest way to add up a
> billion numbers(from 1 to 10^9 i.e the first billion numbers) in
> Mathematica?
>
> Ofcourse the answer is n(n+1)/2, but is there any other way in
> Mathematica other than the following one:
>
> Total@@Range[10^9]

That's not a good way to approach the problem because Range will  
create a list of a billion elements which is expensive, or more  
likely going to run out of memory.

Use Sum

Sum[i,{i,10^9}]

Regards,

Ssezi


  • Prev by Date: Re: change filename automatically in Export Command
  • Next by Date: Re: Means
  • Previous by thread: Re: fastest way to add up a billion numbers
  • Next by thread: Re: fastest way to add up a billion numbers