Slide 1

Slide 1 text

The Monty Hall Problem @mathiasverraes

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Don't use thinking when you can use programming — Alan Turing1 1 Supposedly

Slide 8

Slide 8 text

data Door = Goat | Car deriving (Eq, Show) type Game = [Door]

Slide 9

Slide 9 text

newGame :: MonadRandom m => m Game newGame = shuffleM [Car, Goat, Goat] newGames :: MonadRandom m => m [Game] newGames = replicateM 100 newGame

Slide 10

Slide 10 text

(|>) = flip ($) play :: Strategy -> Game -> Door play strategy game = game |> pickDoor |> revealGoat |> strategy

Slide 11

Slide 11 text

pickDoor :: Game -> Game pickDoor = id -- Assume we always pick -- the first door, it -- doesn't matter anyway.

Slide 12

Slide 12 text

revealGoat :: Game -> Game revealGoat [choice, Goat, x] = [choice, x] revealGoat [choice, x, Goat] = [choice, x]

Slide 13

Slide 13 text

type Strategy = Game -> Door stay :: Strategy stay [firstChoice, alternative] = firstChoice switch :: Strategy switch [firstChoice, alternative] = alternative

Slide 14

Slide 14 text

do game <- newGame return $ play stay game) -- Goat do game <- newGame return $ play switch game -- Car

Slide 15

Slide 15 text

playAll :: Strategy -> [Game] -> Int playAll strategy games = map (play strategy) games |> filter (==Car) |> length

Slide 16

Slide 16 text

do gs <- newGames return $ playAll stay gs -- 32 do gs <- newGames return $ playAll switch gs -- 68

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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/

Slide 20

Slide 20 text

Thanks :-) @mathiasverraes