Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by Ovid (Cardinal)
on Jan 24, 2002 at 00:07 UTC ( [id://141008]=note: print w/replies, xml ) Need Help??


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

$ perl -e '$sum += $_ for ( 1..1000000 );print $sum' 500000500000

Update: Whoops! :) Here's a brute force solution:

$ perl -e 'for(1..1_000_000){$sum+=$_ for(split//)};print $sum' 27000001

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found