Mercurial > rlm
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/rlm/jen.clj Thu Jul 19 10:56:39 2012 -0500 1.3 @@ -0,0 +1,136 @@ 1.4 +(ns rlm.jen) 1.5 + 1.6 +(defn select-cells [n total-groups] 1.7 + (map (fn [_] (int (* total-groups (Math/random)))) (range n))) 1.8 + 1.9 +(defn all-selected? [selections n] 1.10 + (= n (count (set selections)))) 1.11 + 1.12 +(defn probability-of-all-selected 1.13 + [n desired total-groups total-trials] 1.14 + (let [trials 1.15 + (map (fn [_] 1.16 + (all-selected? 1.17 + (select-cells n total-groups) desired)) 1.18 + (range total-trials)) 1.19 + prob 1.20 + (/ (count (filter identity trials)) total-trials)] 1.21 + prob)) 1.22 + 1.23 +(defn your-problem [up-to trials-per-test] 1.24 + (print "selections probability of getting all 15\n") 1.25 + (dorun 1.26 + (map 1.27 + (fn [n] 1.28 + (let [prob 1.29 + (probability-of-all-selected 1.30 + n 15 15 trials-per-test)] 1.31 + (printf "%10d %1.3f\n" n (float prob)))) 1.32 + (range up-to)))) 1.33 + 1.34 + 1.35 +;; rlm.jen> (your-problem 100 1000) 1.36 +;; selections probability of getting all 15 1.37 +;; 0 0.000 1.38 +;; 1 0.000 1.39 +;; 2 0.000 1.40 +;; 3 0.000 1.41 +;; 4 0.000 1.42 +;; 5 0.000 1.43 +;; 6 0.000 1.44 +;; 7 0.000 1.45 +;; 8 0.000 1.46 +;; 9 0.000 1.47 +;; 10 0.000 1.48 +;; 11 0.000 1.49 +;; 12 0.000 1.50 +;; 13 0.000 1.51 +;; 14 0.000 1.52 +;; 15 0.000 1.53 +;; 16 0.000 1.54 +;; 17 0.000 1.55 +;; 18 0.001 1.56 +;; 19 0.000 1.57 +;; 20 0.001 1.58 +;; 21 0.004 1.59 +;; 22 0.005 1.60 +;; 23 0.012 1.61 +;; 24 0.008 1.62 +;; 25 0.028 1.63 +;; 26 0.031 1.64 +;; 27 0.049 1.65 +;; 28 0.045 1.66 +;; 29 0.056 1.67 +;; 30 0.100 1.68 +;; 31 0.113 1.69 +;; 32 0.125 1.70 +;; 33 0.159 1.71 +;; 34 0.152 1.72 +;; 35 0.203 1.73 +;; 36 0.216 1.74 +;; 37 0.259 1.75 +;; 38 0.285 1.76 +;; 39 0.283 1.77 +;; 40 0.331 1.78 +;; 41 0.371 1.79 +;; 42 0.420 1.80 +;; 43 0.421 1.81 +;; 44 0.456 1.82 +;; 45 0.491 1.83 +;; 46 0.527 1.84 +;; 47 0.558 1.85 +;; 48 0.534 1.86 +;; 49 0.568 1.87 +;; 50 0.580 1.88 +;; 51 0.605 1.89 +;; 52 0.668 1.90 +;; 53 0.676 1.91 +;; 54 0.678 1.92 +;; 55 0.706 1.93 +;; 56 0.726 1.94 +;; 57 0.732 1.95 +;; 58 0.743 1.96 +;; 59 0.755 1.97 +;; 60 0.761 1.98 +;; 61 0.789 1.99 +;; 62 0.804 1.100 +;; 63 0.798 1.101 +;; 64 0.837 1.102 +;; 65 0.825 1.103 +;; 66 0.832 1.104 +;; 67 0.865 1.105 +;; 68 0.871 1.106 +;; 69 0.880 1.107 +;; 70 0.894 1.108 +;; 71 0.892 1.109 +;; 72 0.892 1.110 +;; 73 0.903 1.111 +;; 74 0.911 1.112 +;; 75 0.917 1.113 +;; 76 0.926 1.114 +;; 77 0.937 1.115 +;; 78 0.922 1.116 +;; 79 0.942 1.117 +;; 80 0.927 1.118 +;; 81 0.936 1.119 +;; 82 0.952 1.120 +;; 83 0.952 1.121 +;; 84 0.960 1.122 +;; 85 0.973 1.123 +;; 86 0.969 1.124 +;; 87 0.952 1.125 +;; 88 0.963 1.126 +;; 89 0.973 1.127 +;; 90 0.971 1.128 +;; 91 0.969 1.129 +;; 92 0.980 1.130 +;; 93 0.968 1.131 +;; 94 0.975 1.132 +;; 95 0.991 1.133 +;; 96 0.980 1.134 +;; 97 0.977 1.135 +;; 98 0.982 1.136 +;; 99 0.988 1.137 +;; nil 1.138 + 1.139 +