解决这种逻辑问题的方法是什么?
解决这样的问题的方法是什么:
A 说 B 说谎
B 说 C 说谎
D 说 B 说谎
C 说 B 说谎
E 说 A 和 D 说谎
有多少人说谎,多少人说真话? 我不是在寻找上述问题的答案,而是在寻找解决这类问题的方法。多谢。
What would be the approach to a kind of problem that sounds like this:
A says B lies
B says C lies
D says B lies
C says B lies
E says A and D lie
How many lie and how many tell the truth?
I am not looking for the answer to the problem above, but the approach to this kind of problem. Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
温馨提示:
将5个方程转化为逻辑命题,你就会找到答案。
Reminder:
Transform the 5 equations into logical propositions, and you will find answers.
求解以下形式的方程
形成图表节点为 Xi 并连接 Xi 和 X j 当且仅当等式 Xi = NOT X j 出现。
现在尝试使用广度优先搜索对图进行双色。
To solve equations of the form
Form a graph with nodes as Xi and connecting Xi and X j iff the equation Xi = NOT X j appears.
Now try to 2-colour the graph using Breadth First Search.
假设你想用一个程序来解决这个问题……如果你有一个相当小的输入集,那么暴力破解实际上很容易。例如,在本例中,您基本上有 5 个布尔变量 - 每个人是否是说真话的人。
将语句编码为测试,然后运行所有可能的组合以查看哪些组合有效。
这显然是一个“愚蠢”的解决方案,对于大型输入集会失败,但它可能比完整的“推理”引擎更容易编码。我经常发现,通过考虑您实际会遇到的问题的大小,您可以少做很多工作:)
Assuming you're looking to solve this with a program... it's actually pretty easy to brute force, if you've got a reasonably small input set. For example, in this case you've basically got 5 Boolean variables - whether each person is a truth-teller or not.
Encode the statements as tests, and then run through every possible combination to see which ones are valid.
This is obviously a "dumb" solution and will fail for large input sets, but it's likely to be rather easier to code than a full "reasoning" engine. Often I find that you can get away with doing a lot less work by taking into account what size of problem you're actually going to encounter :)
使用逻辑编程语言,例如 Prolog。它们是专门为解决此类问题而设计的。
其他替代方案包括功能逻辑语言和模型检查器。
Use a logic programming language such as Prolog. They are specifically designed to solve such problems.
Other alternatives include functional-logic languages and model checkers.