-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEx1.3.fsx
37 lines (27 loc) · 796 Bytes
/
Ex1.3.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
open System
let rand = new Random()
let rollDice() =
rand.Next(1,7)
let rollPair() =
(rollDice(), rollDice())
let rollX x =
[1..x]
|>List.map (fun x-> rollDice())
//Probability of a six in four rolls of a dice.
[0..1000000]
|>List.map (fun x-> rollX 4)
|>List.map (fun x-> x |>List.tryFindIndex(fun y -> y = 6))
|>List.filter (function Some x -> true | _ -> false)
|>List.length |> float
|>fun x-> x/1000000.0
let rollPairX x =
[1..x]
|>List.map (fun x-> rollPair())
//Probability of a pair of sixes in 24 rolls of a dice
[0..100000]
|>List.map (fun x-> rollPairX 24)
|>List.map(fun x -> x |>List.tryFindIndex(fun (a,b) -> a = 6 && b = 6))
|>List.filter(function Some x -> true | _ -> false)
|>List.length |> float
|>fun x-> x/100000.0
1.0/sqrt(28000.0)