Probabilistic choice: Difference between revisions

m
→‎{{header|Sidef}}: minor code simplifications
m (→‎{{header|Sidef}}: minor code simplifications)
Line 2,632:
{{trans|Perl}}
<lang ruby>define TRIALS = 1e4;
 
 
func prob_choice_picker(options) {
var n = 0;
Line 2,645:
}
}
 
 
var ps = Hash.new(
aleph => 1/5,
beth => 1/6,
Line 2,654:
waw => 1/10,
zayin => 1/11
);
 
 
ps{:heth} = (1 - ps.values.sum);
 
 
var picker = prob_choice_picker(ps);
var results = Hash.new;()
 
 
range(0, TRIALS).eachtimes {
results{picker()}  := 0 ++;
}
 
 
say "Event Occurred Expected Difference";
for k,v in (results.sort_by {|k| results{k} }.reverse.each) { |pair|
varprintf(k,"%-6s v) %f = %f pair...; %f\n",
printf("%-6s %f %f %f\n",
k, v/TRIALS, ps{k},
abs(v/TRIALS - ps{k})
2,747

edits