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
3k
How to Find the Bar
mathiasverraes
1
2.1k
Designed Stickiness
mathiasverraes
1
2.2k
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.8k
Modelling Heuristics
mathiasverraes
1
3k
Object Reorientation
mathiasverraes
6
2.8k
Small Controlled Experiments
mathiasverraes
1
4.1k
Other Decks in Technology
See All in Technology
AIとともに歩んでいくデザイナーの役割の変化
lycorptech_jp
PRO
0
510
20251007: What happens when multi-agent systems become larger? (CyberAgent, Inc)
ornew
1
460
ビズリーチ求職者検索におけるPLMとLLMの活用 / Search Engineering MEET UP_2-1
visional_engineering_and_design
1
160
ソフトウェアエンジニアの生成AI活用と、これから
lycorptech_jp
PRO
0
530
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
8.9k
Introdução a Service Mesh usando o Istio
aeciopires
0
220
LLMプロダクトの信頼性を上げるには?LLM Observabilityによる、対話型音声AIアプリケーションの安定運用
ivry_presentationmaterials
0
590
AWS Top Engineer、浮いてませんか? / As an AWS Top Engineer, Are You Out of Place?
yuj1osm
2
220
Biz職でもDifyでできる! 「触らないAIワークフロー」を実現する方法
igarashikana
2
620
サイバーエージェント流クラウドコスト削減施策「みんなで金塊堀太郎」
kurochan
4
2.1k
業務効率化をさらに加速させる、ノーコードツールとStep Functionsのハイブリッド化
smt7174
2
150
能登半島災害現場エンジニアクロストーク 【JAWS FESTA 2025 in 金沢】
ditccsugii
0
910
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.2k
Designing for humans not robots
tammielis
254
26k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Code Reviewing Like a Champion
maltzj
526
40k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Music & Morning Musume
bryan
46
6.8k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.7k
Documentation Writing (for coders)
carmenintech
75
5.1k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Faster Mobile Websites
deanohume
310
31k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.2k
Agile that works and the tools we love
rasmusluckow
331
21k
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