Page 3 of 3
Re: re: Yep, I have a Math Degree now
Posted: December 21, 2005 • 1:29 pm
by zarathoustra
litlkeck wrote:
c) for c, I would use ML, since anyone could download sml and check the answer out. Code and result follows:
- fun sum(x,y) = if x = y then x else x + sum(x+1, y);
val sum = fn : int * int -> int
- sum(1, 1000000000);
val it = 500000000500000000: int
bad answer.
Gauss did something similar in few seconds without a computer when he was 7.
Re: re: Yep, I have a Math Degree now
Posted: December 21, 2005 • 1:36 pm
by zarathoustra
DrPaul wrote:Assuming we are summing over integers and the probem is in base 10, a quick and easy way to sum all the integers between 1 and 1000000000 is to use the fact that the
sum over k for k = 1 to N is N^2/2 + N/2.
In this case, N is 10^9, so the sum is 10^18/2 + 10^9/2 = 5E17 + 5E8 = 500000000500000000. No programming necessary. Same as litlkeck's result.
I had to derive this formula a long time ago.
More simple: all numbers from 1 to 1000000000 is an arithmetic serie.
The sum of the members of an arithmetic serie: ((first + last) * how many) / 2.
((1 + 1000000000) * 1000000000) / 2 = 500000000500000000
re: Yep, I have a Math Degree now
Posted: December 21, 2005 • 2:52 pm
by Jim the old guy
I was going to post that but Z beat me to the punch.
And if you believe that, I have a nice little bridge in Brooklyn for sale.
Re: re: Yep, I have a Math Degree now
Posted: December 21, 2005 • 6:17 pm
by litlkeck
zarathoustra wrote:
More simple: all numbers from 1 to 1000000000 is an arithmetic serie.
The sum of the members of an arithmetic serie: ((first + last) * how many) / 2.
((1 + 1000000000) * 1000000000) / 2 = 500000000500000000
Zarathoustra, yes, I'm familiar with Guass' Law. In fact, when I was referring, in a previous post, to my knowledge of series, I was thinking directly of that. I was just trying to demonstrate some knowledge in both Math and Computer Science. Also, another reason for the code was so others could run it and check it out for themselves.
~Keck
Re: re: Yep, I have a Math Degree now
Posted: December 21, 2005 • 6:39 pm
by Mr. Thomas Malloy
zarathoustra wrote:DrPaul wrote:Assuming we are summing over integers and the probem is in base 10, a quick and easy way to sum all the integers between 1 and 1000000000 is to use the fact that the
sum over k for k = 1 to N is N^2/2 + N/2.
In this case, N is 10^9, so the sum is 10^18/2 + 10^9/2 = 5E17 + 5E8 = 500000000500000000. No programming necessary. Same as litlkeck's result.
I had to derive this formula a long time ago.
More simple: all numbers from 1 to 1000000000 is an arithmetic serie.
The sum of the members of an arithmetic serie: ((first + last) * how many) / 2.
((1 + 1000000000) * 1000000000) / 2 = 500000000500000000
Yeah what he said... Also if you didn't know, I heard that one plus one equaled two. Hey Jim, How much is that bridge your selling?
re: Yep, I have a Math Degree now
Posted: December 22, 2005 • 5:19 am
by zarathoustra
I'm selling the eiffel tower, if a scrap merchant needs cheap steel.
MP me for more details.

re: Yep, I have a Math Degree now
Posted: December 22, 2005 • 8:28 am
by Jim the old guy
re: Yep, I have a Math Degree now
Posted: December 22, 2005 • 9:21 pm
by DrPaul
More simple: all numbers from 1 to 1000000000 is an arithmetic serie.
The sum of the members of an arithmetic serie: ((first + last) * how many) / 2.
I wouldn't call it simpler. It's exactly the same thing.
((1+N)*N)/2 = N^2/2 + N/2. You recognize it as an arithmetic series, I recognize it as a sum over k from 1 to N. Different name, same sum same result.
Re: re: Yep, I have a Math Degree now
Posted: December 23, 2005 • 5:53 am
by zarathoustra
DrPaul wrote:I wouldn't call it simpler. It's exactly the same thing.
((1+N)*N)/2 = N^2/2 + N/2. You recognize it as an arithmetic series, I recognize it as a sum over k from 1 to N. Different name, same sum same result.
3 operations vs 4 operations

re: Yep, I have a Math Degree now
Posted: December 23, 2005 • 7:54 am
by Jim the old guy
It's what I refer to as "the same thing only different."
re: Yep, I have a Math Degree now
Posted: December 23, 2005 • 10:44 am
by DrPaul
3 operations vs 4 operations
Well, if you want to be that way about it,
(N^2+N)/2. I expanded my expression for clarity and ease of
writing it in scientific notation.
Your way:
(1.000000001E9)*1E9/2
My way:
1E18/2 + 1E9/2
It's just a matter of style. Whatever works for ya.