No such thing as a small change | |
PerlMonks |
Re: Finding sum of all digits from 1 to 1 million.by bmcatt (Friar) |
on Jan 24, 2002 at 00:31 UTC ( [id://141014]=note: print w/replies, xml ) | Need Help?? |
Ummm... You're actually close, although you're off by 1. Fencepost error - you're terminating the loop one too early, so you're not including 1e6 in the loop. When in doubt, let perl figure out the right way to do it for you:
A slightly modified version:
Golfers invited to make this even nicer (not to mention make it run faster...)
In Section
Seekers of Perl Wisdom
|
|