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.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.8k
Property Based Testing
mathiasverraes
1
2.8k
Towards Modelling Processes
mathiasverraes
3
5.9k
Modelling Heuristics
mathiasverraes
1
3.1k
Object Reorientation
mathiasverraes
6
2.9k
Small Controlled Experiments
mathiasverraes
1
4.2k
Other Decks in Technology
See All in Technology
Three-Legged OAuth in AgentCore Gateway
hironobuiga
2
190
Databricks (と気合い)で頑張るAI Agent 運用
kameitomohiro
0
230
Getting started with Google Antigravity
meteatamel
0
360
20260222ねこIoTLT ねこIoTLTをふりかえる
poropinai1966
0
200
今、求められるデータエンジニア
waiwai2111
2
1.4k
AWS Bedrock Guardrails / 機密情報の入力・出力をブロックする — Blocking Sensitive Information Input/Output
kazuhitonakayama
2
170
マイグレーションガイドに書いてないRiverpod 3移行話
taiju59
0
100
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
94k
React 19時代のコンポーネント設計ベストプラクティス
uhyo
17
6.8k
欲しいを叶える個人開発の進め方 / How to Run an Indie Project That Brings Your Ideas to Life
endohizumi
0
340
「静的解析」だけで終わらせない。 SonarQube の最新機能 × AIで エンジニアの開発生産性を本気で上げる方法
xibuka
2
270
AITuberKit+Bedrock AgentCoreで作る 3Dキャラクターエージェント
yokomachi
2
1.6k
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
530
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
350
Prompt Engineering for Job Search
mfonobong
0
180
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
The Limits of Empathy - UXLibs8
cassininazir
1
230
Design in an AI World
tapps
0
160
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
180
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
460
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
190
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
300
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