Dice game probabilities: Difference between revisions

m
→‎optimized: increased the displayed digits, changed a comment.
m (Rust - reformatted with rustfmt)
m (→‎optimized: increased the displayed digits, changed a comment.)
Line 1,761:
This REXX version is an optimized and reduced version of the first part of the 1<sup>st</sup> REXX example.
<lang rexx>/*REXX pgm computes and displays the probabilities of a two─player S─sided, N─dice game.*/
numeric digits 100 /*increase│decreaseincrease/decrease forto heart's desire. */
call game 9 4, 6 6 /*1st player: 9 dice, 4 sides; 2nd player: 6 dice, 6 sides*/
call game 5 10, 6 7 /* " " 5 " 10 " " " 6 " 7 " */
Line 1,780:
do j=w.1 to w.1*s.1; winP= winP + p.1.j * low.j
end /*j*/
say 'The probability for first player to win is ' format(winP*100, , 30digits()%2) "%."
say /* */
return /*displayshow 301/2 decimalof digits────┘100 dec. digits────┘ */
/*──────────────────────────────────────────────────────────────────────────────────────*/
prob: procedure; parse arg n,s,,@ $; #.= 0; pow= s**n
Line 1,795:
Player 1 has 9 dice with 4 sides each.
Player 2 has 6 dice with 6 sides each.
The probability for first player to win is 57.31440767829800829475308641975331440767829800829475308641975308641975308641975309 %.
 
Player 1 has 5 dice with 10 sides each.
Player 2 has 6 dice with 7 sides each.
The probability for first player to win is 64.27886287176261591683737218335927886287176261591683737218335897457691948082856633 %.
</pre>