$ 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.
In reply to (Ovid) Re: Finding sum of all digits from 1 to 1 million.
by Ovid
in thread Finding sum of all digits from 1 to 1 million.
by vladb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |