Calculating Probabity - Dice Game problem

Tell us what’s happening:
The challenge says that diceGame should return 0.5731441, but my function returns 0.5172414. It seems like I’m calculating the probability correctly, but maybe there’s something I’m missing.

**Your code so far**

const mean = arr => arr.reduce((a, b) => a + b, 0) / arr.length
const scale = (val, max, newMax) => newMax / max * val

function diceGame() {
  const peterMean = mean([1,2,3,4]) * 9 // the average number Peter will roll
  const colinMean = mean([1,2,3,4,5,6]) * 6 // the average number Colin will roll
  return scale(peterMean, peterMean + colinMean, 1).toFixed(7)

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15

Challenge: Problem 205: Dice Game

Link to the challenge:

I’m no math wizard, so I can’t tell you off the top of my head the algorithm for calculating the final result but I do know that it probably does not involve simple averages. From the little I do remember from my discrete mathematics course way back when, this seems like it would involve finding the probability of combinations. And for some reason the term “probability distribution” is coming to mind. Oh, how I don’t miss those things :slight_smile:

The point is that this is not a simple problem to solve and you need to know something about the mathematics of probabilities to solve it. I may have been able to solve it at one point in my education, but that was long ago and I haven’t really needed to do any advanced probabilities since, so use it or lose it as they say.

Intuitively I know that Peter has better odds, but don’t ask me how to figure that out. If you don’t know a lot about the mathematics of probabilities like me then you’ll probably need to brush up on the subject first before attempting to answer this. This is one of those challenges where coding the answer is not the hardest part, it’s figuring out the algorithm that is the real challenge.

1 Like

Yeah, I guess I know nothing about probability mathematics haha.
Mine is more calculating what percentage of the time Peter will win if they play hundreds of games I guess?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.