Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- type Prize = Car | Goat
- type Door = Door of Prize
- type Result = Win | Lose
- let rand = new Random(DateTime.UtcNow.Ticks |> int)
- let newGame () =
- [| Door Car; Door Goat; Door Goat |]
- |> Array.sortBy (fun _ -> rand.NextDouble())
- let reveal (doors : Door[]) choice =
- { 0..2 }
- |> Seq.filter ((<>) choice)
- |> Seq.filter (fun idx -> doors.[idx] <> Door Car)
- |> Seq.head
- let play strategy (doors : Door[]) =
- let choice = rand.Next(doors.Length)
- let revealed = reveal doors choice
- let choice = strategy choice revealed
- if doors.[choice] = Door Car then Win else Lose
- let strategyA choice _ = choice
- let strategyB choice revealed =
- { 0..2 }
- |> Seq.filter (fun idx -> idx <> choice && idx <> revealed)
- |> Seq.head
- let getResults strategy =
- { 1..1000 }
- |> Seq.filter (fun _ -> newGame() |> play strategy |> ((=) Win))
- |> Seq.length
- let resultsA = getResults strategyA
- let resultsB = getResults strategyB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement