关于直觉
今天又見到這個智力問題了:
假設你參加了一個游戲節目,現在要從三個密封的箱子中選擇一個。其中兩個箱子是空的,另一個箱子里面有大獎(你偶像的簽名^^)。你并不知道獎在哪一個箱 子里,但主持人知道。游戲節目的主持人先要你選擇一個箱子,接著他把你沒有選的空箱子打開,以證明它是空的。最后主持人給你換箱子的機會,你可以把你所選 擇的箱子換成另一個沒有打開的箱子。此時你該不該換箱子?
我的直覺告訴我,換與不換概率都是1/2.因為沒有選擇的那兩個箱子里必定至少有一個是空的,這是個確定事件,所以,無論是否把它糾出來,對我的選擇的 正確率都是沒有影響的.而主持人指出那個空箱子的過程,那個箱子是正確的概率就應該平均分布到剩下的兩個箱子中去了--概率他老人家應該是公平的吧,大概 不會偏向某一個箱子吧:)
回答這個問題的大致分為兩派,一派選換,一派選不換(廢話嘛,就倆答案...),我對自己的答案頗有信心,但在說服不同意見者方面沒有多少信心--大家也知道,網上爭吵一般是不會出現什么結果的,于是就寫了段代碼,讓程序說話:
Program.cs
using?System;
namespace?SureNoChange
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????int?timesToTry?=?100000;
????????????int?winsWithChange?=?SimulateChange(timesToTry);
????????????Console.WriteLine("Wins?after?change?decision:?{0}/{1}",?winsWithChange,?timesToTry);
????????????int?winsWithOutChange?=?SimulateNoChange(timesToTry);
????????????Console.WriteLine("Wins?without?change?decision:?{0}/{1}",?winsWithOutChange,?timesToTry);
????????????Console.ReadKey();
????????}
????????private?static?int?SimulateChange(int?timesToTry)
????????{
????????????int?timesWin?=?0;
????????????for?(int?i?=?0;?i?<?timesToTry;?i++)
????????????{
????????????????Game?game?=?new?Game();
????????????????game.PlayerSelectAnOption();
????????????????game.RemoveOneWrongOption();
????????????????game.ChangeChoice();
????????????????if?(game.Win)
????????????????{
????????????????????timesWin++;
????????????????}
????????????}
????????????return?timesWin;
????????}
????????private?static?int?SimulateNoChange(int?timesToTry)
????????{
????????????int?timesWin?=?0;
????????????for?(int?i?=?0;?i?<?timesToTry;?i++)
????????????{
????????????????Game?game?=?new?Game();
????????????????game.PlayerSelectAnOption();
????????????????game.RemoveOneWrongOption();
????????????????if?(game.Win)
????????????????{
????????????????????timesWin++;
????????????????}
????????????}
????????????return?timesWin;
????????}
????}
}
Game.cs
using?System;
using?System.Collections.Generic;
namespace?SureNoChange
{
????class?Game
????{
????????Random?r;
????????Choice?prize;
????????Choice?choice;
????????Choice?open;
????????public?Game()
????????{
????????????r?=?new?Random();
????????????prize?=?GetRandomChoice();
????????}
????????/**////?<summary>
????????///?玩家隨機選擇一個箱子
????????///?</summary>
????????internal?void?PlayerSelectAnOption()
????????{
????????????choice?=?GetRandomChoice();
????????}
????????/**////?<summary>
????????///?從未被選擇的,不是答案的箱子里打開一個
????????///?</summary>
????????internal?void?RemoveOneWrongOption()
????????{
????????????List<Choice>?openable?=?new?List<Choice>();
????????????openable.AddRange(AllChoices);
????????????openable.Remove(choice);
????????????openable.Remove(prize);
????????????open?=?openable[r.Next(openable.Count)];
????????}
????????private?Choice?GetRandomChoice()
????????{
????????????return?AllChoices[r.Next(3)];
????????}
????????/**////?<summary>
????????///?從先前選擇的,打開的箱子以外的所有箱子里再隨機選擇一個
????????///?</summary>
????????internal?void?ChangeChoice()
????????{
????????????List<Choice>?rest?=?new?List<Choice>();
????????????rest.AddRange(AllChoices);
????????????rest.Remove(open);
????????????rest.Remove(choice);
????????????Choice?newChoice?=?rest[r.Next(rest.Count)];
????????????choice?=?newChoice;
????????}
????????internal?bool?Win
????????{
????????????get
????????????{
????????????????return?choice?==?prize;
????????????}
????????}
????????static?List<Choice>?allChoices;
????????static?List<Choice>?AllChoices
????????{
????????????get
????????????{
????????????????if?(allChoices?==?null)
????????????????{
????????????????????allChoices?=?new?List<Choice>();
????????????????????allChoices.AddRange((Choice[])Enum.GetValues(typeof(Choice)));
????????????????}
????????????????return?allChoices;
????????????}
????????}
????}
}
Choice.cs
namespace?SureNoChange
{
????enum?Choice
????{
????????A,
????????B,
????????C,
????}
}
但是,結果卻是:
Wins?after?change?decision:?66924/100000
Wins?without?change?decision:?35009/100000
暈了,我的直覺居然錯了!更改選擇的話,得到獎品的可能性是2/3,不改的話,是1/3!
如果對這個宏觀的"概率坍縮"的直覺都能犯這么大的錯誤,那些搞量子物理的,一再被實驗結果打擊,豈不會瘋掉...
假設你參加了一個游戲節目,現在要從三個密封的箱子中選擇一個。其中兩個箱子是空的,另一個箱子里面有大獎(你偶像的簽名^^)。你并不知道獎在哪一個箱 子里,但主持人知道。游戲節目的主持人先要你選擇一個箱子,接著他把你沒有選的空箱子打開,以證明它是空的。最后主持人給你換箱子的機會,你可以把你所選 擇的箱子換成另一個沒有打開的箱子。此時你該不該換箱子?
我的直覺告訴我,換與不換概率都是1/2.因為沒有選擇的那兩個箱子里必定至少有一個是空的,這是個確定事件,所以,無論是否把它糾出來,對我的選擇的 正確率都是沒有影響的.而主持人指出那個空箱子的過程,那個箱子是正確的概率就應該平均分布到剩下的兩個箱子中去了--概率他老人家應該是公平的吧,大概 不會偏向某一個箱子吧:)
回答這個問題的大致分為兩派,一派選換,一派選不換(廢話嘛,就倆答案...),我對自己的答案頗有信心,但在說服不同意見者方面沒有多少信心--大家也知道,網上爭吵一般是不會出現什么結果的,于是就寫了段代碼,讓程序說話:
Program.cs
using?System;
namespace?SureNoChange
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????int?timesToTry?=?100000;
????????????int?winsWithChange?=?SimulateChange(timesToTry);
????????????Console.WriteLine("Wins?after?change?decision:?{0}/{1}",?winsWithChange,?timesToTry);
????????????int?winsWithOutChange?=?SimulateNoChange(timesToTry);
????????????Console.WriteLine("Wins?without?change?decision:?{0}/{1}",?winsWithOutChange,?timesToTry);
????????????Console.ReadKey();
????????}
????????private?static?int?SimulateChange(int?timesToTry)
????????{
????????????int?timesWin?=?0;
????????????for?(int?i?=?0;?i?<?timesToTry;?i++)
????????????{
????????????????Game?game?=?new?Game();
????????????????game.PlayerSelectAnOption();
????????????????game.RemoveOneWrongOption();
????????????????game.ChangeChoice();
????????????????if?(game.Win)
????????????????{
????????????????????timesWin++;
????????????????}
????????????}
????????????return?timesWin;
????????}
????????private?static?int?SimulateNoChange(int?timesToTry)
????????{
????????????int?timesWin?=?0;
????????????for?(int?i?=?0;?i?<?timesToTry;?i++)
????????????{
????????????????Game?game?=?new?Game();
????????????????game.PlayerSelectAnOption();
????????????????game.RemoveOneWrongOption();
????????????????if?(game.Win)
????????????????{
????????????????????timesWin++;
????????????????}
????????????}
????????????return?timesWin;
????????}
????}
}
Game.cs
using?System;
using?System.Collections.Generic;
namespace?SureNoChange
{
????class?Game
????{
????????Random?r;
????????Choice?prize;
????????Choice?choice;
????????Choice?open;
????????public?Game()
????????{
????????????r?=?new?Random();
????????????prize?=?GetRandomChoice();
????????}
????????/**////?<summary>
????????///?玩家隨機選擇一個箱子
????????///?</summary>
????????internal?void?PlayerSelectAnOption()
????????{
????????????choice?=?GetRandomChoice();
????????}
????????/**////?<summary>
????????///?從未被選擇的,不是答案的箱子里打開一個
????????///?</summary>
????????internal?void?RemoveOneWrongOption()
????????{
????????????List<Choice>?openable?=?new?List<Choice>();
????????????openable.AddRange(AllChoices);
????????????openable.Remove(choice);
????????????openable.Remove(prize);
????????????open?=?openable[r.Next(openable.Count)];
????????}
????????private?Choice?GetRandomChoice()
????????{
????????????return?AllChoices[r.Next(3)];
????????}
????????/**////?<summary>
????????///?從先前選擇的,打開的箱子以外的所有箱子里再隨機選擇一個
????????///?</summary>
????????internal?void?ChangeChoice()
????????{
????????????List<Choice>?rest?=?new?List<Choice>();
????????????rest.AddRange(AllChoices);
????????????rest.Remove(open);
????????????rest.Remove(choice);
????????????Choice?newChoice?=?rest[r.Next(rest.Count)];
????????????choice?=?newChoice;
????????}
????????internal?bool?Win
????????{
????????????get
????????????{
????????????????return?choice?==?prize;
????????????}
????????}
????????static?List<Choice>?allChoices;
????????static?List<Choice>?AllChoices
????????{
????????????get
????????????{
????????????????if?(allChoices?==?null)
????????????????{
????????????????????allChoices?=?new?List<Choice>();
????????????????????allChoices.AddRange((Choice[])Enum.GetValues(typeof(Choice)));
????????????????}
????????????????return?allChoices;
????????????}
????????}
????}
}
Choice.cs
namespace?SureNoChange
{
????enum?Choice
????{
????????A,
????????B,
????????C,
????}
}
但是,結果卻是:
Wins?after?change?decision:?66924/100000
Wins?without?change?decision:?35009/100000
暈了,我的直覺居然錯了!更改選擇的話,得到獎品的可能性是2/3,不改的話,是1/3!
如果對這個宏觀的"概率坍縮"的直覺都能犯這么大的錯誤,那些搞量子物理的,一再被實驗結果打擊,豈不會瘋掉...
轉載于:https://www.cnblogs.com/deerchao/archive/2008/02/05/1065147.html
總結
- 上一篇: 使用FileStream读写文件[通俗易
- 下一篇: 蛤蜊的功效与作用 蛤蜊有什么营养价值