Re: fastest way to add up a billion numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg73937] Re: [mg73880] fastest way to add up a billion numbers
- From: János <janos.lobb at yale.edu>
- Date: Sat, 3 Mar 2007 01:11:22 -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]
>
> 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)
- References:
- fastest way to add up a billion numbers
- From: "Raj" <rajanikanth@gmail.com>
- fastest way to add up a billion numbers