my %buckets = (
w => {
count => 4,
scale => 10.5,
},
x => {
count => 6,
scale => 7,
},
y => {
count => 12,
scale => 3,
},
z => {
count => 18,
scale => 2,
},
);
for %buckets.values -> $arg_for {
$arg_for<array> = [ ( 0 .. $arg_for<count> ) »*« $arg_for<scale> ];
}
my int @results;
my int $target = 35;
for %buckets<w><array>.kv -> $i, $w {
say "To 4: $i";
last if $w > $target;
for %buckets<x><array>.kv -> $j, $x {
say " To 6: $j";
last if ($w, $x).sum > $target;
for %buckets<y><array>.kv -> $k, $y {
last if ($w, $x, $y).sum > $target;
for %buckets<z><array>.kv -> $l, $z {
if( $target == ($w, $x, $y, $z).sum ) {
@results.push( [$i, $j, $k, $l] );
}
}
}
}
}
for @results.kv -> $idx, $result {
say "$idx: $result.join(' | ')";
}
I assume all those temporaries that I cleaned out were there for
speed, in which case this will run slower, but they were too
unsightly to keep around.
Regards,
--
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;