文官洗碗安天下,武将打怪定乾坤。多么美好的年代,思之令人泪落。

学军中学推理社2017届招新试题

时间:2016-01-23 / 分类:个人日志,娱乐天地,学习园地,挑战智慧 / 浏览:5698 / 3个评论 发表评论

这份试题共10道,环环相扣,单看一道题或几道题,答不出结果。
只有把题目全看完,并作出正确的假设和推理,才能答对。

image

以下是用python代码写的算法:

# -*- coding: utf-8 -*-

import itertools

A = 'A'
B = 'B'
C = 'C'
D = 'D'

def Q1():
    options = {
        A : A,
        B : B,
        C : C,
        D : D,
    }
    option = options[answer[1]]
    return option == answer[1]

def Q2():
    options = {
        A : C,
        B : D,
        C : A,
        D : B,
    }
    option = options[answer[2]]
    return option == answer[5]

def Q3():
    options = {
        A : answer[3],
        B : answer[6],
        C : answer[2],
        D : answer[4],
    }
    option = options[answer[3]]
    values = options.values()
    values.remove(option)
    return option not in values

def Q4():
    options = {
        A : (answer[1], answer[5]),
        B : (answer[2], answer[7]),
        C : (answer[1], answer[9]),
        D : (answer[6], answer[10]),
    }
    option = options[answer[4]]
    return option[0] == option[1]

def Q5():
    options = {
        A : answer[8],
        B : answer[4],
        C : answer[9],
        D : answer[7],
    }
    option = options[answer[5]]
    return option == answer[5]

def Q6():
    options = {
        A : (answer[2], answer[4]),
        B : (answer[1], answer[6]),
        C : (answer[3], answer[10]),
        D : (answer[5], answer[9]),
    }
    option = options[answer[6]]
    return len(set(list(option) + [answer[8]])) == 1

def Q7():
    options = {
        A : answer.count(C),
        B : answer.count(B),
        C : answer.count(A),
        D : answer.count(D),
    }
    option = options[answer[7]]
    return option == min(options.values())

def Q8():
    options = {
        A : answer[7],
        B : answer[5],
        C : answer[2],
        D : answer[10],
    }
    option = options[answer[8]]
    return abs(ord(option) - ord(answer[1])) != 1

def Q9():
    options = {
        A : answer[6],
        B : answer[10],
        C : answer[2],
        D : answer[9],
    }
    option = options[answer[9]]
    assume1 = (answer[1] == answer[6])
    assume2 = (option == answer[5])
    return assume1 != assume2

def Q10():
    options = {
        A : 3,
        B : 2,
        C : 4,
        D : 1,
    }
    option = options[answer[10]]
    keys = options.keys()
    counts = [answer.count(key) for key in keys]
    return option == abs(max(counts) - min(counts))


#获取10道题答案的全排列
answers = itertools.product([A, B, C, D], repeat=10)
for answer in answers:
    #为了让代码更容易看懂,加了个下标占位符
    answer = [''] + list(answer)
    if Q1() and Q2() and Q3() and Q4() and Q5() and \
       Q6() and Q7() and Q8() and Q9() and Q10():
            print ''.join(answer)
            break

执行结果为:BCACACDABA

标签: , , ,
本文链接: 学军中学推理社2017届招新试题
版权所有: 破博客, 转载请注明本文出处。

3个评论

  1. lth
    2016/02/27 23:51:01

    :?:

  2. txh
    2016/01/25 10:26:53

    :sad: :sad: :sad: 碉堡了大神

发表评论

*

* (显示gravatar头像)

Ctrl+Enter快捷回复

© 2019 破博客 all rights reserved.