網上看到這鍋:
"Fill in number 1 to 9, without repetition."
職業病發:
#!/usr/bin/perl
use List::Permutor;
my $permutor = List::Permutor->new( 1..9 );
while ( my @permutation = $permutor->next() ) {
$attempt++;
$v12 = $permutation[0] . $permutation[1];
$v3 = $permutation[2];
$v45 = $permutation[3] . $permutation[4];
$v67 = $permutation[5] . $permutation[6];
$v89 = $permutation[7] . $permutation[8];
if ( $v12 * $v3 == $v45 ) {
if ( $v45 + $v67 == $v89 ) { last; }
}
}
print "An answer found at attempt \#$attempt:\n";
print "\n";
print " $v12\n";
print "x $v3\n";
print "----\n";
print " $v45\n";
print "+ $v67\n";
print "----\n";
print " $v89\n";
$ time perl soudoku.pl
An answer found at attempt #27076:
17
x 4
----
68
+ 25
----
93
real 0m0.266s
user 0m0.239s
sys 0m0.020s
好啦!零北自己知道自己很沒品啦……
No comments:
Post a Comment