Mercurial > rlm
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-selected10 [n desired total-groups total-trials]11 (let [trials12 (map (fn [_]13 (all-selected?14 (select-cells n total-groups) desired))15 (range total-trials))16 prob17 (/ (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 (dorun23 (map24 (fn [n]25 (let [prob26 (probability-of-all-selected27 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 1534 ;; 0 0.00035 ;; 1 0.00036 ;; 2 0.00037 ;; 3 0.00038 ;; 4 0.00039 ;; 5 0.00040 ;; 6 0.00041 ;; 7 0.00042 ;; 8 0.00043 ;; 9 0.00044 ;; 10 0.00045 ;; 11 0.00046 ;; 12 0.00047 ;; 13 0.00048 ;; 14 0.00049 ;; 15 0.00050 ;; 16 0.00051 ;; 17 0.00052 ;; 18 0.00153 ;; 19 0.00054 ;; 20 0.00155 ;; 21 0.00456 ;; 22 0.00557 ;; 23 0.01258 ;; 24 0.00859 ;; 25 0.02860 ;; 26 0.03161 ;; 27 0.04962 ;; 28 0.04563 ;; 29 0.05664 ;; 30 0.10065 ;; 31 0.11366 ;; 32 0.12567 ;; 33 0.15968 ;; 34 0.15269 ;; 35 0.20370 ;; 36 0.21671 ;; 37 0.25972 ;; 38 0.28573 ;; 39 0.28374 ;; 40 0.33175 ;; 41 0.37176 ;; 42 0.42077 ;; 43 0.42178 ;; 44 0.45679 ;; 45 0.49180 ;; 46 0.52781 ;; 47 0.55882 ;; 48 0.53483 ;; 49 0.56884 ;; 50 0.58085 ;; 51 0.60586 ;; 52 0.66887 ;; 53 0.67688 ;; 54 0.67889 ;; 55 0.70690 ;; 56 0.72691 ;; 57 0.73292 ;; 58 0.74393 ;; 59 0.75594 ;; 60 0.76195 ;; 61 0.78996 ;; 62 0.80497 ;; 63 0.79898 ;; 64 0.83799 ;; 65 0.825100 ;; 66 0.832101 ;; 67 0.865102 ;; 68 0.871103 ;; 69 0.880104 ;; 70 0.894105 ;; 71 0.892106 ;; 72 0.892107 ;; 73 0.903108 ;; 74 0.911109 ;; 75 0.917110 ;; 76 0.926111 ;; 77 0.937112 ;; 78 0.922113 ;; 79 0.942114 ;; 80 0.927115 ;; 81 0.936116 ;; 82 0.952117 ;; 83 0.952118 ;; 84 0.960119 ;; 85 0.973120 ;; 86 0.969121 ;; 87 0.952122 ;; 88 0.963123 ;; 89 0.973124 ;; 90 0.971125 ;; 91 0.969126 ;; 92 0.980127 ;; 93 0.968128 ;; 94 0.975129 ;; 95 0.991130 ;; 96 0.980131 ;; 97 0.977132 ;; 98 0.982133 ;; 99 0.988134 ;; nil