Probabilistic choice: Difference between revisions

Added Easylang
No edit summary
(Added Easylang)
 
(2 intermediate revisions by 2 users not shown)
Line 942:
stdout.print(item, "\t", timesFound[item] / trials, "\t", probTable[item], "\n")
}</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
name$[] = [ "aleph " "beth " "gimel " "daleth" "he " "waw " "zayin " "heth " ]
probs[] = [ 1 / 5 1 / 6 1 / 7 1 / 8 1 / 9 1 / 10 1 / 11 0 ]
for i = 1 to 7
cum += probs[i]
cum[] &= cum
.
cum[] &= 1
probs[8] = 1 - cum[7]
len act[] 8
n = 1000000
for i to n
h = randomf
j = 1
while h > cum[j]
j += 1
.
act[j] += 1
.
print "Name Ratio Expected"
print "---------------------"
numfmt 4 6
for i to 8
print name$[i] & " " & act[i] / n & " " & probs[i]
.
</syntaxhighlight>
 
{{out}}
<pre>
Name Ratio Expected
---------------------
aleph 0.2000 0.2000
beth 0.1661 0.1667
gimel 0.1424 0.1429
daleth 0.1252 0.1250
he 0.1111 0.1111
waw 0.1003 0.1000
zayin 0.0913 0.0909
heth 0.0637 0.0635
</pre>
 
=={{header|Elixir}}==
Line 4,006 ⟶ 4,048:
end loop;
end randdist;</syntaxhighlight>
{{out}}
<pre>
$ spar randdist
aleph 2.00260000000000E-01 2.00000000000000E-01
beth 1.66376000000000E-01 1.66666666666667E-01
gimel 1.42698000000000E-01 1.42857142857143E-01
daleth 1.25408000000000E-01 1.25000000000000E-01
he 1.11311000000000E-01 1.11111111111111E-01
waw 9.97980000000000E-02 1.00000000000000E-01
zayin 9.09570000000000E-02 9.09090909090909E-02
heth 6.31920000000000E-02 rest</pre>
 
=={{header|Stata}}==
Line 4,154 ⟶ 4,207:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./fmt" for Fmt
 
var letters = ["aleph", "beth", "gimel", "daleth", "he", "waw", "zayin", "heth"]
2,023

edits