MathGroup Archive 2007

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

Search the Archive

Re: fastest way to add up a billion numbers


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]
>
> Thanks,
>
> Raj
>

Here is a newbie reply:

z[n_] = RSolve[{y[1] == 1,
     y[n] == y[n - 1] + n},
    y[n], n]

Timing[z[10^9]]
{0.0001319999999971344*
    Second,
   {{y[1000000000] ->
      500000000500000000}}}

J=E1nos


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a 
corpse.
(S. Lem: His Master Voice)



  • Prev by Date: Re: Integrals involving square roots
  • Next by Date: Re: Plot3D
  • Previous by thread: Re: fastest way to add up a billion numbers
  • Next by thread: Re: fastest way to add up a billion numbers