in reply to (OT?) n(n-1)/2
If you're just doing this for Perl education, don't bother with useless mathematical optimizations. In real life, you can often sacrifice a bit of speed for ease of coding.
my $a = 0; $a += $_ for 1..1000; print "Answer: $a\n";
If this isn't about Perl programming, or about programming at all, you're posting in the wrong place :)
P.S. With Perl Golf, of course mathematic principles are a lot more important: $foo && ($foo % 9 || 9) is shorter than substr($foo, 0, 1) + substr($foo, 1, 1) (and do it again if the answer's >9)
++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
- Whreq
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Perl Puzzle, was Re: (OT?) n(n-1)/2
by merlyn (Sage) on Mar 03, 2002 at 13:07 UTC | |
by Juerd (Abbot) on Mar 03, 2002 at 15:26 UTC | |
by little (Curate) on Mar 03, 2002 at 14:11 UTC | |
by Juerd (Abbot) on Mar 03, 2002 at 15:34 UTC | |
by dvergin (Monsignor) on Mar 03, 2002 at 15:01 UTC |