解决这种逻辑问题的方法是什么?

发布于 2024-11-06 20:11:03 字数 167 浏览 0 评论 0原文

解决这样的问题的方法是什么:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蓝海似她心 2024-11-13 20:11:04
A -> !B
B -> !C
D -> !B
C -> !B
E -> !A & !D

温馨提示:

X -> Y  <=>  !X | Y

将5个方程转化为逻辑命题,你就会找到答案。

A -> !B
B -> !C
D -> !B
C -> !B
E -> !A & !D

Reminder:

X -> Y  <=>  !X | Y

Transform the 5 equations into logical propositions, and you will find answers.

不乱于心 2024-11-13 20:11:04

求解以下形式的方程

X1 = NOT X 3

X5 = NOT X 2

等等

形成图表节点为 Xi 并连接 Xi 和 X j 当且仅当等式 Xi = NOT X j 出现。

现在尝试使用广度优先搜索对图进行双色。

To solve equations of the form

X1 = NOT X 3

X5 = NOT X 2

etc

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.

揽清风入怀 2024-11-13 20:11:04

假设你想用一个程序来解决这个问题……如果你有一个相当小的输入集,那么暴力破解实际上很容易。例如,在本例中,您基本上有 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 :)

帅的被狗咬 2024-11-13 20:11:04

使用逻辑编程语言,例如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文