view src/rlm/jen.clj @ 8:7240d7a5f959

random files :)
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jul 2012 10:56:39 -0500
parents
children
line wrap: on
line source
1 (ns rlm.jen)
3 (defn select-cells [n total-groups]
4 (map (fn [_] (int (* total-groups (Math/random)))) (range n)))
6 (defn all-selected? [selections n]
7 (= n (count (set selections))))
9 (defn probability-of-all-selected
10 [n desired total-groups total-trials]
11 (let [trials
12 (map (fn [_]
13 (all-selected?
14 (select-cells n total-groups) desired))
15 (range total-trials))
16 prob
17 (/ (count (filter identity trials)) total-trials)]
18 prob))
20 (defn your-problem [up-to trials-per-test]
21 (print "selections probability of getting all 15\n")
22 (dorun
23 (map
24 (fn [n]
25 (let [prob
26 (probability-of-all-selected
27 n 15 15 trials-per-test)]
28 (printf "%10d %1.3f\n" n (float prob))))
29 (range up-to))))
32 ;; rlm.jen> (your-problem 100 1000)
33 ;; selections probability of getting all 15
34 ;; 0 0.000
35 ;; 1 0.000
36 ;; 2 0.000
37 ;; 3 0.000
38 ;; 4 0.000
39 ;; 5 0.000
40 ;; 6 0.000
41 ;; 7 0.000
42 ;; 8 0.000
43 ;; 9 0.000
44 ;; 10 0.000
45 ;; 11 0.000
46 ;; 12 0.000
47 ;; 13 0.000
48 ;; 14 0.000
49 ;; 15 0.000
50 ;; 16 0.000
51 ;; 17 0.000
52 ;; 18 0.001
53 ;; 19 0.000
54 ;; 20 0.001
55 ;; 21 0.004
56 ;; 22 0.005
57 ;; 23 0.012
58 ;; 24 0.008
59 ;; 25 0.028
60 ;; 26 0.031
61 ;; 27 0.049
62 ;; 28 0.045
63 ;; 29 0.056
64 ;; 30 0.100
65 ;; 31 0.113
66 ;; 32 0.125
67 ;; 33 0.159
68 ;; 34 0.152
69 ;; 35 0.203
70 ;; 36 0.216
71 ;; 37 0.259
72 ;; 38 0.285
73 ;; 39 0.283
74 ;; 40 0.331
75 ;; 41 0.371
76 ;; 42 0.420
77 ;; 43 0.421
78 ;; 44 0.456
79 ;; 45 0.491
80 ;; 46 0.527
81 ;; 47 0.558
82 ;; 48 0.534
83 ;; 49 0.568
84 ;; 50 0.580
85 ;; 51 0.605
86 ;; 52 0.668
87 ;; 53 0.676
88 ;; 54 0.678
89 ;; 55 0.706
90 ;; 56 0.726
91 ;; 57 0.732
92 ;; 58 0.743
93 ;; 59 0.755
94 ;; 60 0.761
95 ;; 61 0.789
96 ;; 62 0.804
97 ;; 63 0.798
98 ;; 64 0.837
99 ;; 65 0.825
100 ;; 66 0.832
101 ;; 67 0.865
102 ;; 68 0.871
103 ;; 69 0.880
104 ;; 70 0.894
105 ;; 71 0.892
106 ;; 72 0.892
107 ;; 73 0.903
108 ;; 74 0.911
109 ;; 75 0.917
110 ;; 76 0.926
111 ;; 77 0.937
112 ;; 78 0.922
113 ;; 79 0.942
114 ;; 80 0.927
115 ;; 81 0.936
116 ;; 82 0.952
117 ;; 83 0.952
118 ;; 84 0.960
119 ;; 85 0.973
120 ;; 86 0.969
121 ;; 87 0.952
122 ;; 88 0.963
123 ;; 89 0.973
124 ;; 90 0.971
125 ;; 91 0.969
126 ;; 92 0.980
127 ;; 93 0.968
128 ;; 94 0.975
129 ;; 95 0.991
130 ;; 96 0.980
131 ;; 97 0.977
132 ;; 98 0.982
133 ;; 99 0.988
134 ;; nil