Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. open System
  2.  
  3. type Prize = Car | Goat
  4. type Door = Door of Prize
  5. type Result = Win | Lose
  6.  
  7. let rand = new Random(DateTime.UtcNow.Ticks |> int)
  8. let newGame () =
  9. [| Door Car; Door Goat; Door Goat |]
  10. |> Array.sortBy (fun _ -> rand.NextDouble())
  11.  
  12. let reveal (doors : Door[]) choice =
  13. { 0..2 }
  14. |> Seq.filter ((<>) choice)
  15. |> Seq.filter (fun idx -> doors.[idx] <> Door Car)
  16. |> Seq.head
  17.  
  18. let play strategy (doors : Door[]) =
  19. let choice = rand.Next(doors.Length)
  20. let revealed = reveal doors choice
  21. let choice = strategy choice revealed
  22. if doors.[choice] = Door Car then Win else Lose
  23.  
  24. let strategyA choice _ = choice
  25. let strategyB choice revealed =
  26. { 0..2 }
  27. |> Seq.filter (fun idx -> idx <> choice && idx <> revealed)
  28. |> Seq.head
  29.  
  30. let getResults strategy =
  31. { 1..1000 }
  32. |> Seq.filter (fun _ -> newGame() |> play strategy |> ((=) Win))
  33. |> Seq.length
  34.  
  35. let resultsA = getResults strategyA
  36. let resultsB = getResults strategyB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement