2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,27 @@
defmodule Probabilistic do
@tries 1000000
@probs [aleph: 1/5,
beth: 1/6,
gimel: 1/7,
daleth: 1/8,
he: 1/9,
waw: 1/10,
zayin: 1/11,
heth: 1759/27720]
def test do
trials = for _ <- 1..@tries, do: get_choice(@probs, :rand.uniform)
IO.puts "Item Expected Actual"
fmt = " ~-8s ~.6f ~.6f~n"
Enum.each(@probs, fn {glyph,expected} ->
actual = length(for ^glyph <- trials, do: glyph) / @tries
:io.format fmt, [glyph, expected, actual]
end)
end
defp get_choice([{glyph,_}], _), do: glyph
defp get_choice([{glyph,prob}|_], ran) when ran < prob, do: glyph
defp get_choice([{_,prob}|t], ran), do: get_choice(t, ran - prob)
end
Probabilistic.test

View file

@ -1,32 +1,32 @@
/*REXX program shows results of probabilistic choices, gen random #s per prob.*/
parse arg trials digits seed . /*obtain the optional arguments from CL*/
if trials=='' | trials==',' then trials=1000000
if digits=='' | digits==',' then digits=15; digits=max(10,digits)
if seed\=='' then call random ,,seed /*for repeatability.*/
names='aleph beth gimel daleth he waw zayin heth totals'
cells=words(names) - 1; high=100000; s=0; !.=0
/*REXX program displays results of probabilistic choices, gen random #s per probability.*/
parse arg trials digits seed . /*obtain the optional arguments from CL*/
if trials=='' | trials=="," then trials=1000000 /*Not specified? Then use the default.*/
if digits=='' | digits=="," then digits=15 /* " " " " " " */
if datatype(seed,'W') then call random ,,seed /*allows repeatability for RANDOM nums.*/
names= 'aleph beth gimel daleth he waw zayin heth totals'
cells=words(names) - 1; high=100000; s=0; !.=0
_=4
do n=1 for 7; _=_+1; prob.n=1/_; Hprob.n=prob.n*high; s=s+prob.n
end /*n*/ /* [↑] determine the probabilities. */
do n=1 for 7; _=_+1; prob.n=1/_; Hprob.n=prob.n*high; s=s+prob.n
end /*n*/ /* [↑] determine the probabilities. */
prob.8=1759/27720; Hprob.8=prob.8*high; s=s+prob.8; prob.9=s; !.9=trials
prob.8=1759/27720; Hprob.8=prob.8*high; s=s+prob.8; prob.9=s; !.9=trials
do j=1 for trials; r=random(1,high) /*generate X number of random numbers.*/
do k=1 for cells /*for each cell, compute percentages. */
if r<=Hprob.k then !.k=!.k+1 /*for each range, bump the counter. */
do j=1 for trials; r=random(1, high) /*generate X number of random numbers.*/
do k=1 for cells /*for each cell, compute percentages. */
if r<=Hprob.k then !.k=!.k+1 /*for each range, bump the counter. */
end /*k*/
end /*j*/
w=digits+6; d=max(length(trials), length('count')) + 4
say centr('name',15) centr('count',d) centr('target %') centr('actual %')
/* [↑] display a formatted header line*/
do i=1 for cells+1 /*show for each of the cells and totals*/
/* [↑] display a formatted header line*/
do i=1 for cells+1 /*show for each of the cells and totals*/
say ' ' left(word(names,i) , 12),
right(!.i , d-2) ' ',
right(!.i , d-2) " ",
left(format(prob.i *100, d), w-2),
left(format(!.i/trials*100, d), w-2)
if i==8 then say centr(,15) centr(,d) centr() centr()
end /*i*/
exit /*stick a fork in it, we are all done.*/
/*────────────────────────────────────────────────────────────────────────────*/
centr: return center(arg(1), word(arg(2) w,1), '')
exit /*stick a fork in it, we are all done.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
centr: return center( arg(1), word(arg(2) w, 1), '')