Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Monty Hall Problem with Haskell
Search
Mathias Verraes
May 04, 2016
Technology
0
2.5k
The Monty Hall Problem with Haskell
5min lightning talk for the SoCraTes Belgium meetup.
Mathias Verraes
May 04, 2016
Tweet
Share
More Decks by Mathias Verraes
See All by Mathias Verraes
On Being Explicit
mathiasverraes
0
2.7k
How to Find the Bar
mathiasverraes
1
1.9k
Designed Stickiness
mathiasverraes
1
1.9k
The World's Shortest and Most Chaotic Introduction to Event Storming
mathiasverraes
1
2.5k
Property Based Testing
mathiasverraes
1
2.5k
Towards Modelling Processes
mathiasverraes
3
5.4k
Modelling Heuristics
mathiasverraes
1
2.6k
Object Reorientation
mathiasverraes
6
2.5k
Small Controlled Experiments
mathiasverraes
1
3.8k
Other Decks in Technology
See All in Technology
CSPが提供しない、フレッツ網をつかった閉域接続サービス&データ持ち込みにつかえるサービス 3選
armaniacs
1
930
Angular Signals under the Hood
fabiangosebrink
0
230
Waffle Festival2024(斉藤裕希)
cybozuinsideout
PRO
3
200
Platform Engineering on Serverless
_kensh
3
440
現場訪問で変わる毎日の開発
andpad
1
210
Multimodal LLMs and foundation models in robotics
keio_smilab
PRO
2
680
組織的なクラウド統制のはじめの一歩 後編
nyankotaro
0
250
シリーズAをリファラル採用中心に走り抜ける / leaner-referral-engineer-2024
corocn
3
1.2k
IBM Cloud Dojo - いまからでも遅くない!IBM Cloudの認定資格を取ろう 2024
6onoda
0
100
AWS でのクラウド時代のログ活用
itotsum
1
130
JAWS-UGの楽しみ方
schwrzktz
1
280
온디바이스 AI 및 로컬 AI의 도전 과제 / Challenges of On-Device AI and Local AI
inureyes
PRO
0
790
Featured
See All Featured
Clear Off the Table
cherdarchuk
86
310k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Happy Clients
brianwarren
92
6.4k
The Power of CSS Pseudo Elements
geoffreycrofte
62
5.1k
Designing on Purpose - Digital PM Summit 2013
jponch
111
6.5k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
136
41k
Documentation Writing (for coders)
carmenintech
60
4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
41
4.5k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
Into the Great Unknown - MozCon
thekraken
15
1.2k
Building Adaptive Systems
keathley
32
1.9k
Building an army of robots
kneath
300
42k
Transcript
The Monty Hall Problem @mathiasverraes
None
None
None
None
None
Don't use thinking when you can use programming — Alan
Turing1 1 Supposedly
data Door = Goat | Car deriving (Eq, Show) type
Game = [Door]
newGame :: MonadRandom m => m Game newGame = shuffleM
[Car, Goat, Goat] newGames :: MonadRandom m => m [Game] newGames = replicateM 100 newGame
(|>) = flip ($) play :: Strategy -> Game ->
Door play strategy game = game |> pickDoor |> revealGoat |> strategy
pickDoor :: Game -> Game pickDoor = id -- Assume
we always pick -- the first door, it -- doesn't matter anyway.
revealGoat :: Game -> Game revealGoat [choice, Goat, x] =
[choice, x] revealGoat [choice, x, Goat] = [choice, x]
type Strategy = Game -> Door stay :: Strategy stay
[firstChoice, alternative] = firstChoice switch :: Strategy switch [firstChoice, alternative] = alternative
do game <- newGame return $ play stay game) --
Goat do game <- newGame return $ play switch game -- Car
playAll :: Strategy -> [Game] -> Int playAll strategy games
= map (play strategy) games |> filter (==Car) |> length
do gs <- newGames return $ playAll stay gs --
32 do gs <- newGames return $ playAll switch gs -- 68
None
module MontyHall where newGame :: MonadRandom m => m Game
newGame = shuffleM [Car, Goat, Goat] import System.Random.Shuffle newGames :: MonadRandom m => m [Game] import Control.Monad.Random.Class newGames = replicateM 100 newGame import Control.Monad pickDoor :: Game -> Game (|>) = flip ($) pickDoor = id data Door = Goat | Car deriving (Eq, Show) revealGoat :: Game -> Game type Game = [Door] revealGoat [choice, Goat, x] = [choice, x] type Strategy = Game -> Door revealGoat [choice, x, Goat] = [choice, x] play :: Strategy -> Game -> Door stay, switch :: Strategy play strategy game = stay [firstChoice, alternative] = firstChoice game switch [firstChoice, alternative] = alternative |> pickDoor |> revealGoat main :: IO() |> strategy main = do (stayCnt, switchCnt) <- do playAll :: Strategy -> [Game] -> Int gs <- newGames playAll strategy games = return (playAll stay gs, playAll switch gs) map (play strategy) games print ("Stay: " ++ show stayCnt) |> filter (==Car) print ("Switch: " ++ show switchCnt) |> length
Full source code: https://gist.github.com/mathiasverraes/ 3a31c912c6efb496566d55ee077dad6f Diagram: Curiouser http://www.curiouser.co.uk/monty/montyhall2.htm Images: AsapScience
http://youtube.com/watch?v=9vRUxbzJZ9Y Inspiration: F# Monty Hall problem by Yan Cui http://theburningmonk.com/2015/09/f-monty-hall-problem/
Thanks :-) @mathiasverraes