Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
31
Task/Probabilistic-choice/Erlang/probabilistic-choice.erl
Normal file
31
Task/Probabilistic-choice/Erlang/probabilistic-choice.erl
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
-module(probabilistic_choice).
|
||||
|
||||
-export([test/0]).
|
||||
|
||||
-define(TRIES, 1000000).
|
||||
|
||||
test() ->
|
||||
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}],
|
||||
random:seed(now()),
|
||||
Trials =
|
||||
[get_choice(Probs,random:uniform()) || _ <- lists:seq(1,?TRIES)],
|
||||
[{Glyph,Expected,(length([Glyph || Glyph_ <- Trials, Glyph_ == Glyph])/?TRIES)}
|
||||
|| {Glyph,Expected} <- Probs].
|
||||
|
||||
get_choice([{Glyph,_}],_) ->
|
||||
Glyph;
|
||||
get_choice([{Glyph,Prob}|T],Ran) ->
|
||||
case (Ran < Prob) of
|
||||
true ->
|
||||
Glyph;
|
||||
false ->
|
||||
get_choice(T,Ran - Prob)
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue