Probabilistic choice: Difference between revisions
Content added Content deleted
m (added a comma to the task's preamble.) |
No edit summary |
||
Line 2,733: | Line 2,733: | ||
═══════════════ ═══════════ ═════════════════════ ═════════════════════ |
═══════════════ ═══════════ ═════════════════════ ═════════════════════ |
||
───totals───► 1000000 100 100 |
───totals───► 1000000 100 100 |
||
</pre> |
|||
=={{header|Ring}}== |
|||
<lang ring> |
|||
# Project : Probabilistic choice |
|||
# Date : 2017/10/01 |
|||
# Author : Gal Zsolt (~ CalmoSoft ~) |
|||
# Email : <calmosoft@gmail.com> |
|||
cnt = list(8) |
|||
item = ["aleph","beth","gimel","daleth","he","waw","zayin","heth"] |
|||
prob = [1/5.0, 1/6.0, 1/7.0, 1/8.0, 1/9.0, 1/10.0, 1/11.0, 1759/27720] |
|||
for trial = 1 to 5000 |
|||
r = random(10)/10 |
|||
p = 0 |
|||
for i = 1 to len(prob) |
|||
p = p + prob[i] |
|||
if r < p |
|||
cnt[i] = cnt[i] + 1 |
|||
loop |
|||
ok |
|||
next |
|||
next |
|||
see "item actual theoretical" + nl |
|||
for i = 1 to len(item) |
|||
see "" + item[i] + " " + cnt[i]/5000 + " " + prob[i] + nl |
|||
next |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
item actual theoretical |
|||
aleph 0.19 0.20 |
|||
beth 0.36 0.17 |
|||
gimel 0.56 0.14 |
|||
daleth 0.64 0.13 |
|||
he 0.73 0.11 |
|||
waw 0.82 0.10 |
|||
zayin 0.90 0.09 |
|||
heth 0.90 0.06 |
|||
</pre> |
</pre> |
||