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
2.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Monty Hall Problem with Haskell
5min lightning talk for the SoCraTes Belgium meetup.
Mathias Verraes
May 04, 2016
More Decks by Mathias Verraes
See All by Mathias Verraes
On Being Explicit
mathiasverraes
0
3.1k
How to Find the Bar
mathiasverraes
1
2.2k
Designed Stickiness
mathiasverraes
1
2.3k
The World's Shortest and Most Chaotic Introduction to Event Storming
mathiasverraes
2
2.8k
Property Based Testing
mathiasverraes
1
2.8k
Towards Modelling Processes
mathiasverraes
3
6k
Modelling Heuristics
mathiasverraes
1
3.1k
Object Reorientation
mathiasverraes
6
3k
Small Controlled Experiments
mathiasverraes
1
4.3k
Other Decks in Technology
See All in Technology
時期が悪い!それでもRaspberry Piを買って遊んで活用するには / 20260627-osc26do-rpi-jikigawarui
akkiesoft
1
960
デジタル・デザイン:次の50年を描く「進化する青写真」
y150saya
0
750
NDIAS CTF 2026 問題解説会資料
bata_24
0
160
技術・能力を向上する原理原則 #きのこセッションa #きのこ2026
bash0c7
0
190
AI時代における最適なQA組織の作り方
ymty
3
330
組織における AI-DLC 実践
askul
0
270
BPaaSで進むAIオペレーションの現在地 AI実装が効く領域とスケーラビリティの選定と実装
kentarofujii
0
250
AI・ロボティクスと自動化社会 / AI, Robotics, and the Automated Society
ks91
PRO
0
130
AWS Summit の片隅で、体育座りしながらコミュニティがにぎわう理由を考えた
k_adachi_01
2
330
“ID沼入口” - 基本とセキュリティから始める、考え続けるためのID管理技術勉強会 告知&イントロ
ritou
0
360
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
240
“詰む”前に仕組みを作れ 〜技術の波に溺れないためのキャッチアップ術〜
takasyou
8
4.9k
Featured
See All Featured
Chasing Engaging Ingredients in Design
codingconduct
0
230
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Tell your own story through comics
letsgokoyo
1
980
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Speed Design
sergeychernyshev
33
1.9k
Into the Great Unknown - MozCon
thekraken
41
2.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Building Applications with DynamoDB
mza
96
7.1k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
440
The Limits of Empathy - UXLibs8
cassininazir
1
380
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