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.7k
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.9k
How to Find the Bar
mathiasverraes
1
2k
Designed Stickiness
mathiasverraes
1
2.1k
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.6k
Modelling Heuristics
mathiasverraes
1
2.8k
Object Reorientation
mathiasverraes
6
2.7k
Small Controlled Experiments
mathiasverraes
1
4k
Other Decks in Technology
See All in Technology
大規模言語モデルとそのソフトウェア開発に向けた応用 (2024年版)
kazato
2
510
三菱電機で社内コミュニティを立ち上げた話
kurebayashi
1
320
RubyでKubernetesプログラミング
sat
PRO
2
120
プロダクトの寿命を延ばすためにエンジニアが考えるべきこと 〜バージョンアップってなんのためにやるのか〜 / Strategies for product longevity
kaonavi
0
100
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
400
.NET 最新アップデート ~ AI とクラウド時代のアプリモダナイゼーション
chack411
0
170
Unlearn Product Development - Unleashed Edition
lemiorhan
PRO
2
170
12 Days of OpenAIから読み解く、生成AI 2025年のトレンド
shunsukeono_am
0
1.1k
Evolving Architecture
rainerhahnekamp
3
240
2025年のARグラスの潮流
kotauchisunsun
0
740
Unsafe.BitCast のすゝめ。
nenonaninu
0
170
MasterMemory v3 最速確認会
yucchiy
0
340
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Building Adaptive Systems
keathley
38
2.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Optimising Largest Contentful Paint
csswizardry
33
3k
Speed Design
sergeychernyshev
25
730
Statistics for Hackers
jakevdp
797
220k
Designing for humans not robots
tammielis
250
25k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
950
Faster Mobile Websites
deanohume
305
30k
Writing Fast Ruby
sferik
628
61k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
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