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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Mathias Verraes
May 04, 2016
Technology
0
2.8k
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
3.1k
How to Find the Bar
mathiasverraes
1
2.1k
Designed Stickiness
mathiasverraes
1
2.3k
The World's Shortest and Most Chaotic Introduction to Event Storming
mathiasverraes
2
2.7k
Property Based Testing
mathiasverraes
1
2.7k
Towards Modelling Processes
mathiasverraes
3
5.9k
Modelling Heuristics
mathiasverraes
1
3k
Object Reorientation
mathiasverraes
6
2.9k
Small Controlled Experiments
mathiasverraes
1
4.2k
Other Decks in Technology
See All in Technology
分析画面のクリック操作をそのままコード化 ! エンジニアとビジネスユーザーが共存するAI-ReadyなBI基盤
ikumi
0
130
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
200
Webhook best practices for rock solid and resilient deployments
glaforge
1
200
プロダクト成長を支える開発基盤とスケールに伴う課題
yuu26
3
1.1k
AIとともに歩む情報セキュリティ / Information Security with AI
kanny
4
3.1k
Embedded SREの終わりを設計する 「なんとなく」から計画的な自立支援へ
sansantech
PRO
2
1.8k
Meshy Proプラン課金した
henjin0
0
180
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
150
GCASアップデート(202510-202601)
techniczna
0
250
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
130
新規事業における「一部だけどコア」な AI精度改善の優先順位づけ
zerebom
0
490
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
680
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
53
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Code Review Best Practice
trishagee
74
20k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
400
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
49k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
So, you think you're a good person
axbom
PRO
2
1.9k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
110
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
The SEO Collaboration Effect
kristinabergwall1
0
350
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