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
ガバメントクラウド(AWS)へのデータ移行戦略の立て方【虎の巻】 / 20251011 Mitsutosi Matsuo
shift_evolve
PRO
2
190
後進育成のしくじり〜任せるスキルとリーダーシップの両立〜
matsu0228
7
3.3k
ニッポンの人に知ってもらいたいGISスポット
sakaik
0
130
AWSでAgentic AIを開発するための前提知識の整理
nasuvitz
1
110
能登半島地震で見えた災害対応の課題と組織変革の重要性
ditccsugii
0
660
Adapty_東京AI祭ハッカソン2025ピッチスライド
shinoyamada
0
280
Wasmのエコシステムを使った ツール作成方法
askua
0
140
綺麗なデータマートをつくろう_データ整備を前向きに考える会 / Let's create clean data mart
brainpadpr
3
450
Vibe Coding Year in Review. From Karpathy to Real-World Agents by Niels Rolland, CEO Paatch
vcoisne
0
130
能登半島地震において デジタルができたこと・できなかったこと
ditccsugii
0
150
AIAgentの限界を超え、 現場を動かすWorkflowAgentの設計と実践
miyatakoji
1
170
エンタメとAIのための3Dパラレルワールド構築(GPU UNITE 2025 特別講演)
pfn
PRO
0
260
Featured
See All Featured
Building an army of robots
kneath
306
46k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Optimizing for Happiness
mojombo
379
70k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Facilitating Awesome Meetings
lara
56
6.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
The Language of Interfaces
destraynor
162
25k
The Invisible Side of Design
smashingmag
302
51k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
How to Ace a Technical Interview
jacobian
280
24k
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