解答2018刑侦推理试题

这是网上很火的2018刑侦推理试题,作为程序员当然想的是如何用编程得出答案.

 1 <?php
 2 error_reporting(0);
 3 $option = array('A','B','C','D');
 4 function check_1($data){
 5     return true;
 6 }
 7 
 8 function check_2($data){
 9     $question = array('A'=>'C','B'=>'D','C'=>'A','D'=>'B');
10     if($question[$data[2]] == $data[5]) return true;
11     return false;
12 }
13 
14 function check_3($data){
15     $question = array('A'=>$data[3],'B'=>$data[6],'C'=>$data[2],'D'=>$data[4]);
16     $answer = $question[$data[3]];
17     unset($question[$data[3]]);
18     if(!in_array($answer,$question)) return true;
19     return false;
20 }
21 
22 function check_4($data){
23     $question = array('A'=>$data[1]==$data[5],'B'=>$data[2]==$data[7],'C'=>$data[1]==$data[9],'D'=>$data[6]==$data[10]);
24     return $question[$data[4]];
25 }
26 
27 function check_5($data){
28     $question = array('A'=>$data[8],'B'=>$data[4],'C'=>$data[9],'D'=>$data[7]);
29     if($question[$data[5]] == $data[5]) return true;
30     return false;
31 }
32 
33 function check_6($data){
34     $question = array('A'=>$data[2]==$data[4] && $data[4]==$data[8],'B'=>$data[1]==$data[6] && $data[6]==$data[8],'C'=>$data[3]==$data[10] && $data[10]==$data[8],'D'=>$data[5]==$data[9] && $data[9]=$data[8]);
35     return $question[$data[6]];    
36 }
37 
38 function check_7($data){
39     $question = array('A'=>'C','B'=>'B','C'=>'A','D'=>'D');
40     $count = array_count_values($data);
41     arsort($count);
42     if(array_pop(array_keys($count))==$question[$data[7]]) return true;
43     return false;
44 }
45 
46 function check_8($data){
47     $map = array('A'=>1,'B'=>2,'C'=>3,'D'=>4);
48     $question = array('A'=>$data[7],'B'=>$data['5'],'C'=>$data['2'],'D'=>$data['10']);
49     if(abs($map[$data[1]] - $map[$question[$data[8]]])>1) return true;
50     return false;
51 }
52 
53 function check_9($data){
54     $question = array('A'=>$data[6],'B'=>$data[10],'C'=>$data[2],'D'=>$data[9]);
55     if(($question[$data[9]] == $data[5])!=($data[1] == $data[6]))return true;
56     return false;
57     
58 }
59 
60 function check_10($data){
61     $question = array('A'=>3,'B'=>2,'C'=>4,'D'=>1);
62     $count = array_count_values($data);
63     arsort($count);
64     $min = array_pop($count);
65     asort($count);
66     $max = array_pop($count);
67     if($question[$data[10]] == $max-$min) return true;
68     return false;
69 }
70 
71 foreach($option as $v[1]){
72     foreach($option as $v[2]){
73         foreach($option as $v[3]){
74             foreach($option as $v[4]){
75                 foreach($option as $v[5]){
76                     foreach($option as $v[6]){
77                         foreach($option as $v[7]){
78                             foreach($option as $v[8]){
79                                 foreach($option as $v[9]){
80                                     foreach($option as $v[10]){
81                                         for($i=1;$i<=10;$i++){
82                                             $answer[$i] = $v[$i];
83                                         }
84                                         for($i=1;$i<=10;$i++){
85                                             $func = "check_".$i;
86                                             if(!$func($answer)) break;
87                                         }
88                                         if($i == 11) {echo implode(' ',$answer)."\r\n";die;}
89                                     }
90                                 }
91                             }
92                         }
93                     }
94                 }
95             }
96         }
97     }
98 }

结果输出:B C A C A C D A B A

 

posted @ 2018-03-09 16:05  尘封的秘密  阅读(259)  评论(0编辑  收藏  举报