アタマも選ぶようにした。これも、同じ牌であるかはまだ見ていない。
パターン数は
COMBIN(13,2) * COMBIN(11,3) * COMBIN(8,3) * COMBIN(5,3) = 7207200
use strict;
use warnings;
if($#ARGV < 0){
print "please specify haipai.\n";
exit;
}
my @haipai = split //, shift;
my @menz;
my $menz_count = 0;
my $head_count = 0;
my $select_head = 0;
print "haipai: @haipai\n";
&select_head([@haipai]);
#&select_menz([@haipai],[@menz]);
sub select_head{
my @haipai = @{ $_[0] };
use strict;
use warnings;
if($#ARGV < 0){
print "please specify haipai.\n";
exit;
}
my @haipai = split //, shift;
my @menz;
my $menz_count = 0;
my $head_count = 0;
my $select_head = 0;
print "haipai: @haipai\n";
&select_head([@haipai]);
#&select_menz([@haipai],[@menz]);
sub select_head{
my @haipai = @{ $_[0] };
my ($i, $j) = (0, 1);
while($i <= $#haipai - 1){
$head_count++;
# print "$head_count: <".$haipai[$i].$haipai[$j].">\n";
my $atama = "<".$haipai[$i].$haipai[$j].">";
my @menz;
my @new_haipai = @haipai;
$new_haipai[$i]=0;
$new_haipai[$j]=0;
@new_haipai = grep { $_ > 0 } @new_haipai;
&select_menz([@new_haipai], [@menz], $atama);
$j++;
if($j>$#haipai){
$i++;
$j=$i+1;
}
}
}
sub select_menz{
my @haipai = @{ $_[0] };
my @menz = @{ $_[1] };
my $atama = $_[2];
my ($i,$j, $k) = (0, 1, 2);
if($#haipai < 2){
$menz_count++;
print "$menz_count: $atama @menz amari:@haipai\n";
return;
}
while($i <= $#haipai - 2){
my @new_menz = @menz;
push @new_menz, "(".$haipai[$i].$haipai[$j].$haipai[$k].")";
my @new_haipai = @haipai;
$new_haipai[$i]=0;
$new_haipai[$j]=0;
$new_haipai[$k]=0;
@new_haipai = grep { $_ > 0 } @new_haipai;
&select_menz([@new_haipai], [@new_menz], $atama);
$k++;
if($k>$#haipai){
$j++;
if($j>$#haipai -1){
$i++;
$j=$i+1;
$k=$j+1;
}else{
$k=$j+1;
}
}
}
}