Last active
May 4, 2020 05:13
-
-
Save obelisk68/d4d3661114c69677b0a67acc233e1406 to your computer and use it in GitHub Desktop.
嘘つき問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imp = ->(p, q) {!p || q} | |
eqv = ->(p, q) {!(!p ^ !q)} | |
def output(say, cond) | |
trans = ->(ary) {"[#{ary.map {|f| f ? "T" : "F"}.join(" ")}]"} | |
puts [trans.(say), trans.(cond)].join(" ") | |
end | |
cond = Array.new(5) | |
result = (1 << 5) - 1 | |
puts "say".center(11) + " " + "cond".center(11) | |
[true, false].repeated_permutation(5) do |say| | |
a, b, c, d, e = say | |
next unless eqv.(a, !b) | |
next unless eqv.(b, !e) | |
next unless eqv.(c, !d) | |
cond[0] = (say.count(false) == 3) | |
cond[1] = (say.count(true) == 3) | |
cond[2] = imp.(!b, !d) | |
cond[3] = imp.(!e, say.count(false) == 3) | |
cond[4] = imp.(!a, d) | |
output(say, cond) | |
acc = 0 | |
cond.each_with_index {|cd, i| acc |= 1 << i if cd} | |
result &= acc | |
end | |
5.times {|i| puts "条件#{i + 1}が確実に言える" if result[i].nonzero?} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#問題 | |
A~Eの5人で論争した結果、次のような、A、B、Cの発言があった。 | |
A「Bはウソをついている」 | |
B「Eはウソをついている」 | |
C「Dはウソをついている」 | |
以上の事ことから判断して確実にいえるのは、次のうちのどれか。 | |
1 ウソつきは3人いる。 | |
2 正直者は3人いる。 | |
3 Bがウソつきであるとき、Dもウソつきである。 | |
4 Eがウソつきであれば、ウソつきはもう2人いる。 | |
5 Aが正直者ならば、Dも正直者である。 | |
#結果 | |
say cond | |
[T F T F T] [F T T T T] | |
[T F F T T] [F T F T T] | |
[F T T F F] [T F T T F] | |
[F T F T F] [T F T T T] | |
条件4が確実に言える | |
#出典 | |
http://rsc.hatenablog.com/entry/2019/10/30/215119 | |
#参考 | |
https://qiita.com/scivola/items/308f9cbf0412bc20650b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment