推理问卷如下
![原始问卷](https://i-blog.csdnimg.cn/blog_migrate/f88c6e7fed315284e9e35b0b1be0a207.jpeg)
解题程序
<?php
$questionAnswer=[];
function question($n){
global $questionAnswer;
$answerOption=['a','b','c','d'];
foreach ($answerOption as $answer ) {
$questionAnswer[$n]=$answer;
if($n<10){
question($n+1);
}else{
if(check()){
var_export($questionAnswer);
echo "\n";
}
}
}
}
function check(){
global $questionAnswer;
$q2Option=['a'=>'c','b'=>'d','c'=>'a','d'=>'b'];
if($q2Option[$questionAnswer[2]]!=$questionAnswer[5]){
return false;
}
$q3Option=['a'=>3,'b'=>6,'c'=>2,'d'=>4];
foreach ($q3Option as $answer => $qNum) {
if($answer!=$questionAnswer[3]){
if($questionAnswer[$qNum]==$questionAnswer[$q3Option[$questionAnswer[3]]]){
return false;
}
}
}
$q4Option=['a'=>[1,5],'b'=>[2,7],'c'=>[1,9],'d'=>[6,10]];
$qNums=$q4Option[$questionAnswer[4]];
if($questionAnswer[$qNums[0]]!=$questionAnswer[$qNums[1]]){
return false;
}
$q5Option=['a'=>8,'b'=>4,'c'=>9,'d'=>7];
if($questionAnswer[$q5Option[$questionAnswer[5]]]!=$questionAnswer[5]){
return false;
}
$q6Option=['a'=>[2,4],'b'=>[1,6],'c'=>[3,10],'d'=>[5,9]];
$qNums=$q6Option[$questionAnswer[6]];
foreach ($qNums as $qNum ) {
if($questionAnswer[$qNum]!=$questionAnswer[8]){
return false;
}
}
$q7Option=['a'=>'c','b'=>'b','c'=>'a','d'=>'d'];
$minMaxLetter = minMaxLetter();
if(!array_key_exists($q7Option[$questionAnswer[7]], $minMaxLetter[0])){
return false;
}
$q8Option=['a'=>7,'b'=>5,'c'=>2,'d'=>10];
if(adjacent($questionAnswer[$q8Option[$questionAnswer[8]]],$questionAnswer[1])){
return false;
}
$q9Option=['a'=>6,'b'=>10,'c'=>2,'d'=>9];
$qNum=$q9Option[$questionAnswer[9]];
$c1=$questionAnswer[1]==$questionAnswer[6];
$c2=$questionAnswer[$qNum]==$questionAnswer[5];
if($c1==$c2){
return false;
}
$q10Option=['a'=>3,'b'=>2,'c'=>4,'d'=>1];
if($q10Option[$questionAnswer[10]]!=$minMaxLetter[2]){
return false;
}
return true;
}
function minMaxLetter(){
global $questionAnswer;
$counter=['a'=>0,'b'=>0,'c'=>0,'d'=>0];
foreach ($questionAnswer as $answer) {
$counter[$answer]++;
}
$min=100;
$max=-100;
foreach ($counter as $answer=>$n) {
if($n<=$min){
if($n==$min){
$minLetter[$answer]=$n;
}else{
$minLetter = [];
$minLetter[$answer]=$n;
}
$min = $n;
}
if($n>=$max){
if($n==$max){
$maxLetter[$answer]=$n;
}else{
$maxLetter = [];
$maxLetter[$answer]=$n;
}
$max = $n;
}
}
return [$minLetter,$maxLetter,$max-$min];
}
function adjacent($a,$b){
return abs(ord($a)-ord($b))==1;
}
echo 'Begin to solve ...',"\n";
$beginTime = time();
question(1);
echo 'used time: ',time()-$beginTime,' seconds',"\n";