关于直觉
今天又見到這個(gè)智力問題了:
假設(shè)你參加了一個(gè)游戲節(jié)目,現(xiàn)在要從三個(gè)密封的箱子中選擇一個(gè)。其中兩個(gè)箱子是空的,另一個(gè)箱子里面有大獎(jiǎng)(你偶像的簽名^^)。你并不知道獎(jiǎng)在哪一個(gè)箱 子里,但主持人知道。游戲節(jié)目的主持人先要你選擇一個(gè)箱子,接著他把你沒有選的空箱子打開,以證明它是空的。最后主持人給你換箱子的機(jī)會(huì),你可以把你所選 擇的箱子換成另一個(gè)沒有打開的箱子。此時(shí)你該不該換箱子?
我的直覺告訴我,換與不換概率都是1/2.因?yàn)闆]有選擇的那兩個(gè)箱子里必定至少有一個(gè)是空的,這是個(gè)確定事件,所以,無論是否把它糾出來,對(duì)我的選擇的 正確率都是沒有影響的.而主持人指出那個(gè)空箱子的過程,那個(gè)箱子是正確的概率就應(yīng)該平均分布到剩下的兩個(gè)箱子中去了--概率他老人家應(yīng)該是公平的吧,大概 不會(huì)偏向某一個(gè)箱子吧:)
回答這個(gè)問題的大致分為兩派,一派選換,一派選不換(廢話嘛,就倆答案...),我對(duì)自己的答案頗有信心,但在說服不同意見者方面沒有多少信心--大家也知道,網(wǎng)上爭吵一般是不會(huì)出現(xiàn)什么結(jié)果的,于是就寫了段代碼,讓程序說話:
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>
????????///?玩家隨機(jī)選擇一個(gè)箱子
????????///?</summary>
????????internal?void?PlayerSelectAnOption()
????????{
????????????choice?=?GetRandomChoice();
????????}
????????/**////?<summary>
????????///?從未被選擇的,不是答案的箱子里打開一個(gè)
????????///?</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>
????????///?從先前選擇的,打開的箱子以外的所有箱子里再隨機(jī)選擇一個(gè)
????????///?</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,
????}
}
但是,結(jié)果卻是:
Wins?after?change?decision:?66924/100000
Wins?without?change?decision:?35009/100000
暈了,我的直覺居然錯(cuò)了!更改選擇的話,得到獎(jiǎng)品的可能性是2/3,不改的話,是1/3!
如果對(duì)這個(gè)宏觀的"概率坍縮"的直覺都能犯這么大的錯(cuò)誤,那些搞量子物理的,一再被實(shí)驗(yàn)結(jié)果打擊,豈不會(huì)瘋掉...
假設(shè)你參加了一個(gè)游戲節(jié)目,現(xiàn)在要從三個(gè)密封的箱子中選擇一個(gè)。其中兩個(gè)箱子是空的,另一個(gè)箱子里面有大獎(jiǎng)(你偶像的簽名^^)。你并不知道獎(jiǎng)在哪一個(gè)箱 子里,但主持人知道。游戲節(jié)目的主持人先要你選擇一個(gè)箱子,接著他把你沒有選的空箱子打開,以證明它是空的。最后主持人給你換箱子的機(jī)會(huì),你可以把你所選 擇的箱子換成另一個(gè)沒有打開的箱子。此時(shí)你該不該換箱子?
我的直覺告訴我,換與不換概率都是1/2.因?yàn)闆]有選擇的那兩個(gè)箱子里必定至少有一個(gè)是空的,這是個(gè)確定事件,所以,無論是否把它糾出來,對(duì)我的選擇的 正確率都是沒有影響的.而主持人指出那個(gè)空箱子的過程,那個(gè)箱子是正確的概率就應(yīng)該平均分布到剩下的兩個(gè)箱子中去了--概率他老人家應(yīng)該是公平的吧,大概 不會(huì)偏向某一個(gè)箱子吧:)
回答這個(gè)問題的大致分為兩派,一派選換,一派選不換(廢話嘛,就倆答案...),我對(duì)自己的答案頗有信心,但在說服不同意見者方面沒有多少信心--大家也知道,網(wǎng)上爭吵一般是不會(huì)出現(xiàn)什么結(jié)果的,于是就寫了段代碼,讓程序說話:
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>
????????///?玩家隨機(jī)選擇一個(gè)箱子
????????///?</summary>
????????internal?void?PlayerSelectAnOption()
????????{
????????????choice?=?GetRandomChoice();
????????}
????????/**////?<summary>
????????///?從未被選擇的,不是答案的箱子里打開一個(gè)
????????///?</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>
????????///?從先前選擇的,打開的箱子以外的所有箱子里再隨機(jī)選擇一個(gè)
????????///?</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,
????}
}
但是,結(jié)果卻是:
Wins?after?change?decision:?66924/100000
Wins?without?change?decision:?35009/100000
暈了,我的直覺居然錯(cuò)了!更改選擇的話,得到獎(jiǎng)品的可能性是2/3,不改的話,是1/3!
如果對(duì)這個(gè)宏觀的"概率坍縮"的直覺都能犯這么大的錯(cuò)誤,那些搞量子物理的,一再被實(shí)驗(yàn)結(jié)果打擊,豈不會(huì)瘋掉...
轉(zhuǎn)載于:https://www.cnblogs.com/deerchao/archive/2008/02/05/1065147.html
總結(jié)
- 上一篇: 使用FileStream读写文件[通俗易
- 下一篇: WebDeploymentSetup使用