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.6k
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.8k
How to Find the Bar
mathiasverraes
1
2k
Designed Stickiness
mathiasverraes
1
2k
The World's Shortest and Most Chaotic Introduction to Event Storming
mathiasverraes
2
2.6k
Property Based Testing
mathiasverraes
1
2.6k
Towards Modelling Processes
mathiasverraes
3
5.5k
Modelling Heuristics
mathiasverraes
1
2.7k
Object Reorientation
mathiasverraes
6
2.6k
Small Controlled Experiments
mathiasverraes
1
3.9k
Other Decks in Technology
See All in Technology
20240911_New_Relicダッシュボード活用例
speakerdeckfk
0
110
持続可能なソフトウェア開発を支える『GitHub CI/CD実践ガイド』
tmknom
7
1.4k
Analytics-Backed App Widget Development - Served with Jetpack Glance
miyabigouji
0
610
Cloud Run と GitHub Template Repository による軽量なアプリケーションプラットフォーム/ #nikkei_tech_talk
nikkei_engineer_recruiting
0
110
より快適なエラーログ監視を目指して
leveragestech
4
1.4k
効果的なオンコール対応と障害対応
ryuichi1208
6
3.1k
『GRANBLUE FANTASY: Relink』最高の「没入感」を実現するカットシーン制作手法とそれを支える技術
cygames
1
140
アプリをリリースできる状態に保ったまま 段階的にリファクタリングするための 戦略と戦術 / Strategies and tactics for incremental refactoring
yanzm
6
1.4k
ネットワークだけ隔離されたコンテナ作成デモ / Kichijoji.pm36
tenforward
1
230
OR学会2024秋_短期収益と将来のオフ方策評価性能を考慮したクーポン割当方策混合比の決定
recruitengineers
PRO
4
460
学術機関におけるID連携とOpenID Connect
fujie
0
250
Tricentisにおけるテスト自動化へのAI活用ご紹介/20240910Shunsuke Katakura
shift_evolve
0
200
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
Building Adaptive Systems
keathley
36
2.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
Building a Scalable Design System with Sketch
lauravandoore
459
32k
Designing the Hi-DPI Web
ddemaree
278
34k
The World Runs on Bad Software
bkeepers
PRO
64
11k
Learning to Love Humans: Emotional Interface Design
aarron
270
40k
Typedesign – Prime Four
hannesfritz
39
2.3k
Speed Design
sergeychernyshev
22
430
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
354
29k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
Web development in the modern age
philhawksworth
205
10k
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