Dice game probabilities: Difference between revisions
m
Rust - reformatted with rustfmt
m (Simplified code) |
m (Rust - reformatted with rustfmt) |
||
Line 1,845:
<lang rust>// Returns a vector containing the number of ways each possible sum of face
// values can occur.
fn get_totals(dice
let mut result = vec![1.0; faces + 1];
for d in 2..=dice {
let mut tmp = vec![0.0; d * faces + 1];
for i in d - 1..result.len() {
for j in 1..=faces {
tmp[i + j] += result[i];
Line 1,859:
}
fn probability(dice1
let totals1 = get_totals(dice1, faces1);
let totals2 = get_totals(dice2, faces2);
let mut wins = 0.0;
let mut total = 0.0;
for i in dice1..totals1.len() {
for j in dice2..totals2.len() {
let n = totals1[i] * totals2[j];
Line 1,873:
}
}
wins / total
}
|