蒙蒂霍尔问题_常见的逻辑难题–骑士和刀,蒙蒂·霍尔和就餐哲学家的问题解释...

蒙蒂霍尔问题

While not strictly related to programming, logic puzzles are a good warm up to your next coding session. You may encounter a logic puzzle in your next technical interview as a way to judge your problem solving skills, so it's worth being prepared.

虽然与编程不严格相关,但逻辑难题是您下一次编码会议的良好准备。 在下一次技术面试中,您可能会遇到逻辑难题,以此来判断您的问题解决能力,因此值得做好准备。

In this article, we've collected a few famous logic puzzles and their solutions. Can you solve them without peeking at the answer?

在本文中,我们收集了一些著名的逻辑难题及其解决方案。 您能不偷看答案就能解决它们吗?

骑士和小刀 (Knights and Knaves)

For this logic puzzle, imagine there are two types of people, knights and knaves. Knights only tell the truth, while Knaves only tell lies.

对于这个逻辑难题,想象一下有两种人,骑士和小刀。 骑士只说实话,而刀只讲谎言。

There are many variations of this puzzle, but most involve asking a question to figure out who is the knight and who is the knave.

这个难题有很多变体,但大多数都涉及问一个问题以弄清楚谁是骑士和谁是刀匠。

红色和蓝色 (Red and Blue)

There are two people standing in front of you, Red and Blue. Blue says, "We are both knaves." Who is really the knight and who is the knave?

有两个人站在你面前,红色和蓝色。 蓝说:“我们都是刀子。” 谁是真正的骑士,谁是最专业的人?

SolutionIt's impossible for Blue to be the knight. If Blue was a knight, the statement, "We are both knaves," would actually be a lie. Therefore, Blue is a knave as his statement is a lie, and Red must be a knight.

解决方案 Blue不可能成为骑士。 如果布鲁是一个骑士,那么“我们都是刀”这样的说法实际上就是谎言。 因此,蓝色是个k夫,因为他的陈述是谎言,而红色必须是个骑士。

两条路 (Two Paths)

You arrive at a fork in the road and need to choose the correct path that leads to your destination. There are two people standing at the fork, and you know that one must be a knight and the other must be a knave.

您到达道路上的岔路口,需要选择通往目的地的正确路径。 有两个人站在叉子上,您知道一个人必须是骑士,另一个人必须是a夫。

What single question could you ask to one of the people to determine the correct path, A or B?

您可以问一个人哪个问题来确定正确的路径A或B?

SolutionThe question you can ask either person is, "What path would the other person tell me is the correct one?" The answer will always be the wrong path to take, and you can safely take the other path.Imagine the correct path is A. If you ask directly, "Which is the correct path?" the knave will say B is correct while the knight will say A.However, when asked which path the other person

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值