#!/usr/local/bin/perl
# (c) 2017-11-14 : Coded by shun kinoshita / knuhs
#
# 問題(八卷直一さんがFacebook上で提示したもの)
# ?*(?-?/?)=10 の?には一桁の異なる整数が入ります。
#
use strict;
my $count=0;
for( my $a=-9; $a<=9; $a++ )
{
for( my $b=-9; $b<=9; $b++ )
{
next if $a==$b ;
for( my $c=-9; $c<=9; $c++ )
{
next if $a==$c | $b==$c ;
for( my $d=-9; $d<=9; $d++ )
{
next if $a==$d | $b==$d | $c==$d | $d==0 ;
next if $a*($b-$c/$d)!=10 ;
$count++;
print "[$count]:($a)*(($b)-($c)/($d))";
my $v = $a * ( $b - $c / $d );
print " = $v\n";
}
}
}
}
print "Total counts = $count\n";
exit;
|