Old stuff/Perl/testsudo.pl
(Deskargatu)
#!/usr/bin/perl -w
use Data::Dumper;
$|=1;
my @sudo;
for my $i(0..8)
{
for my $j(0..8)
{
my $input= <STDIN>;
chomp($input);
if ($input) { $sudo[$i][$j] = $input; }
else
{
$sudo[$i][$j]= "123456789";
}
# $sudo[$i][$j]= "0";
}
}
$sudo[0][2]= "6";
$sudo[0][4]= "8";
$sudo[0][5]= "4";
$sudo[0][7]= "9";
$sudo[0][8]= "2";
$sudo[1][1]= "4";
$sudo[1][4]= "2";
$sudo[1][5]= "7";
$sudo[1][6]= "1";
$sudo[1][7]= "8";
$sudo[2][3]= "3";
$sudo[2][7]= "4";
$sudo[3][2]= "1";
$sudo[3][6]= "4";
$sudo[4][0]= "5";
$sudo[4][1]= "6";
$sudo[4][2]= "8";
$sudo[4][3]= "4";
$sudo[4][5]= "1";
$sudo[4][6]= "7";
$sudo[4][7]= "2";
$sudo[4][8]= "3";
$sudo[5][2]= "2";
$sudo[5][6]= "8";
$sudo[6][1]= "5";
$sudo[6][5]= "3";
$sudo[7][1]= "2";
$sudo[7][2]= "7";
$sudo[7][3]= "9";
$sudo[7][4]= "4";
$sudo[7][7]= "3";
$sudo[8][0]= "8";
$sudo[8][1]= "1";
$sudo[8][3]= "2";
$sudo[8][4]= "7";
$sudo[8][6]= "9";
sub printgame()
{
for my $i(0..8)
{
for my $j(0..8)
{
if ($sudo[$i][$j] =~ /\d\d/) { print "x "; }
else
{
print $sudo[$i][$j]." ";
}
}
print "\n";
}
print "\n\n";
}
sub check()
{
for my $i(0..8)
{
for my $j(0..8)
{
if ( $sudo[$i][$j] =~ /../) { return 0; }
}
}
return 1;
}
printgame;
while(!check())
{
for my $i(0..8)
{
for my $j(0..8)
{
if ( $sudo[$i][$j] =~ /^(.)$/)
{
my $elt = $1;
# print "Element: $elt ($i,$j)\n";
for my $temp(0..8) {
if ($j != $temp) {$sudo[$i][$temp] =~ s/$elt//g; }
if ($i != $temp) {$sudo[$temp][$j] =~ s/$elt//g; } }
}
}
}
for my $i(0..2)
{
for my $j(0..2)
{
# ($i*3,$j*3) = debut du carre
for my $x($i*3..$i*3+2)
{
for my $y($j*3..$j*3+2)
{
# print "Check $x, $y\n";
if ($sudo[$x][$y] =~ /^(.)$/) { $elt=$1; #print "\tElement simple: ";
for my $delx($i*3..$i*3+2)
{
for my $dely($j*3..$j*3+2)
{
if ($x != $delx or $y != $dely) {
$sudo[$delx][$dely] =~ s/$elt//g;
}
}
}
}
}
}
}
}
printgame;
select(undef,undef,undef,0.5);
}
print "La matrice est pas bonne". check()."\n";