sub subset_sum { my $targ = shift; my $re = join '', map '(' . '.' x $_ . ')?', @_; return map defined() ? length : (), (1 x $targ) =~ /^$re$/; }