Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Finding sum of all digits from 1 to 1 million.

by rbc (Curate)
on Jan 24, 2002 at 02:11 UTC ( [id://141042]=note: print w/replies, xml ) Need Help??


in reply to Finding sum of all digits from 1 to 1 million.

use the formul ...
<RB> (n+1)*n/2

Why does this work?
look at this ... 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 is the same as

1 + 10 +
2 + 9 +
3 + 8 +
4 + 7 +
5 + 6
which is the same as
11 + 11 + 11 + 11 + 11
which is 11*5 = (n+1)*n/2 where n = 10
  • Comment on Re: Finding sum of all digits from 1 to 1 million.

Replies are listed 'Best First'.
Re: Re: Finding sum of all digits from 1 to 1 million.
by little (Curate) on Jan 24, 2002 at 16:40 UTC
    Sorry, but 10 is not a gidit , its a number, composed of the digits 1 and 0.
    so your solution should look alike:
    0+9
    1+8
    2+7
    3+6
    4+5
    which is 45
    But anyway, I wouldn't be surprised if another one shows up presenting a "correct" solution of "42" grin

    Have a nice day
    All decision is left to your taste

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://141042]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found