in reply to Math with Perl, equation combinations:

Here's the straight-ahead dumb way to do it:

#!/usr/bin/perl -w use strict; my $target=shift; X: for my $x (1 .. 20) { for my $y (1..20) { my $z = $target - $x - $y; next X if $z<1 || $z>20; print "($x,$y,$z)$/"; } }
Uhhh, this wasn't homework, was it? ;-)

Update: Remove a bogosity from code. U 2: samtregar, there is Steal This Code.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Math with Perl, equation combinations:
by samtregar (Abbot) on May 11, 2002 at 03:07 UTC
    Uhhh, this wasn't homework, was it? ;-)

    Oh, no, I bet he was just wondering. Desperately wondering.

    We should trace his IP and find his professor...

    -sam