In comp.lang.perl.misc Xah Lee <[EMAIL PROTECTED]> wrote:
> a year ago i wrote this perl program as part of a larger program.
 
> sub combo ($) {
>    my $max=$_[0];
>    my %hh=();
>    for (my $j=1; $j < $max; ++$j) {
>        for (my $i=1; $i <= $max; ++$i) {
>            my $m = (($i+$j)-1)%$max+1;
>            if ($i < $m){ $hh{"$i,$m"}=[$i,$m];}
>        }
>    }
>    return \%hh;
> }
 
Well, it's not obfuscated Perl. It is, however, an obfuscated algorithm.

Sane people would use something along the lines of:

sub combo {
    my $max = shift;
    my %hh=();
    for my $i ( 1 .. $max ) {
        for my $j ( $i + 1 .. $max ) {
            $hh{"$i,$j"} = [$i, $j];
        }
    }
    return \%hh;
}

 
Axel

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to