use strict;
use warnings;
@_ = (2..10,'J','Q','K','A');
comb('', 4, 2..4,6..10,'J','Q','K','A',@_,@_,@_);
sub comb {
my ($str, $depth, @items) = @_;
if (!$depth--) { interpret($str); return; }
comb("$str $items[$_]", $depth, @items[($_+1)..$#items]) for (0..$#items)
}
sub interpret {
my @cards = split / /, "5$_[0]";
# Do whatever with @cards;
}
####
@_ = (2..4,6..9,'A');
comb('', 4, @_,@_,@_,@_);
##
##
comb('', 4, 2..4,6..9,'A');
##
##
use strict;
use warnings;
comb('', 4, 1..4,6..9);
sub comb {
my ($str, $depth, @items) = @_;
if (!$depth--) { interpret($str); return; }
comb("$str $items[$_]", $depth, @items[($_+1)..$#items]) for (0..$#items)
}
sub interpret {
my @cards = split / /, "5$_[0]";
@cards = sort {$b <=> $a} @cards;
my $flag = 1;
for (0..3) { $flag = 0 if $cards[$_+1] != ($cards[$_]-1); }
return if $flag;
for (perm(@cards)) {
return if sum(split //) == 15;
}
print join " ", @cards;
}
BEGIN {
my @c_out;
sub perm {
@c_out = ();
permute('', $_, @_) for (0..$#_);
return @c_out;
}
sub permute {
my ($str, $depth, @chars) = @_;
if (!$depth--) {
push @c_out, $str.$_ for @chars;
}
else {
permute($str.$chars[$_], $depth, @chars[($_+1)..($#chars)])
for (0..$#chars);
}
}
}
sub sum { my $n; $n += $_ for @_; return $n; }