----- Original Message ----
> From: Larry Wall <[EMAIL PROTECTED]>
>
> You should not need "my" on the right side of a ->.  Also, you should
> be able to write $arg_for<count> for constant subscripts.

Thanks!  The revised script is below for those who are interested.

Cheers,
Ovid

-

my %buckets = (
    'w' => {
        'count' => 4,
        'scale' => 10.5,
        'array' => [],
     },
    'x' => {
        'count' => 6,
        'scale' => 7,
        'array' => [],
     },
    'y' => {
        'count' => 12,
        'scale' => 3,
        'array' => [],
     },
    'z' => {
        'count' => 18,
        'scale' => 2,
        'array' => [],
     },
);

for %buckets.values -> $arg_for {
    for 0 .. $arg_for<count> -> $index {
        $arg_for<array>.push($index * $arg_for<scale>);
    }
}

my int @results;
my int $target = 35;

my $w_bucket = %buckets<w>;
for 0 .. $w_bucket<count> -> $i {
    say "To 4: $i";
    my $w = $w_bucket<array>[$i];

    last if $w > $target;

    my $x_bucket = %buckets<x>;
    for 0 .. $x_bucket<count> -> $j {
        say "  To 6: $j";
        my $x = $x_bucket<array>[$j];

        last if ($w, $x).sum > $target;

        my $y_bucket = %buckets<y>;
        for 0 .. $y_bucket<count> -> $k {
            my $y = $y_bucket<array>[$k];

            last if ($w, $x, $y).sum > $target;

            my $z_bucket = %buckets<z>;
            for 0 .. $z_bucket<count> -> $l {
                my $z = $z_bucket<array>[$l];

                if( $target == ($w, $x, $y, $z).sum ) {
                    @results.push( [$i, $j, $k, $l] );
                }
            }
        }
    }
}

my $counter = 0;
for @results -> $result {
    say "$counter: " ~ $result.join(" | ");
    $counter++;
}





Reply via email to