Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by jeffa (Bishop)
on Jan 24, 2002 at 00:06 UTC ( [id://141007]=note: print w/replies, xml ) Need Help??


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

perl -le "print 1_000_000 * 1_000_001 / 2"
Didn't need Math::BigInt, so i would say there is a problem in the code.

(that formula is one of Guass's, by the way)

UPDATE: details details! :D

seriously, sorry about that, does this help?

$sum += split('',$_) for (1..1_000_000);

You rule, tye! ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--

H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Finding sum of all digits from 1 to 1 million.
by Anonymous Monk on Jan 24, 2002 at 00:17 UTC
    That tells you the sum of all integers from 1 to 1 million. It doesn't give you the sum of all the digits in those numbers. To illustrate the difference: The sum of all numbers from 1 to 15 is 105 (1 + 2 + 3...+15) The sum of all digits in those numbers is 66 (1 + 2 + 3...+ (1 + 0)... + (1+ 5)) -Beth

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-28 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found