Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg73926] Re: fastest way to add up a billion numbers
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 3 Mar 2007 01:05:20 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <es92b2$3oj$1@smc.vnet.net>

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]

Does not work on my 32-bit system.

In[2]:=
Total@@Range[10^9]//Timing

 From In[1]:=

No more memory available.
Mathematica kernel has shut down.
Try quitting other applications and then retry.

> Thanks,
> 
> Raj
> 
> 
What about Sum?

In[1]:=
Timing[Sum[i, {i, 10^9}]]

Out[1]=
{0.11 Second, 500000000500000000}

Regards,
Jean-Marc


  • Prev by Date: Re: Problems with simplify and Sqrt[a^2]
  • Next by Date: Re: NIntegrate - Gaussian quadrature more exact than thought
  • Previous by thread: Re: fastest way to add up a billion numbers
  • Next by thread: Re: fastest way to add up a billion numbers