Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
41
Task/Probabilistic-choice/Sidef/probabilistic-choice.sidef
Normal file
41
Task/Probabilistic-choice/Sidef/probabilistic-choice.sidef
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
define TRIALS = 1e4;
|
||||
|
||||
func prob_choice_picker(options) {
|
||||
var n = 0;
|
||||
var a = [];
|
||||
options.each { |k,v|
|
||||
n += v;
|
||||
a << [n, k];
|
||||
}
|
||||
func {
|
||||
var r = 1.rand;
|
||||
a.first{|e| r <= e[0] }[1];
|
||||
}
|
||||
}
|
||||
|
||||
var ps = Hash(
|
||||
aleph => 1/5,
|
||||
beth => 1/6,
|
||||
gimel => 1/7,
|
||||
daleth => 1/8,
|
||||
he => 1/9,
|
||||
waw => 1/10,
|
||||
zayin => 1/11
|
||||
)
|
||||
|
||||
ps{:heth} = (1 - ps.values.sum)
|
||||
|
||||
var picker = prob_choice_picker(ps)
|
||||
var results = Hash()
|
||||
|
||||
TRIALS.times {
|
||||
results{picker()} := 0 ++;
|
||||
}
|
||||
|
||||
say "Event Occurred Expected Difference";
|
||||
for k,v in (results.sort_by {|k| results{k} }.reverse) {
|
||||
printf("%-6s %f %f %f\n",
|
||||
k, v/TRIALS, ps{k},
|
||||
abs(v/TRIALS - ps{k})
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue