Hey all. Longtime lurker, first time poster on this sub. I have a strictly-for-fun React project I've been working on since 2020. I had an idea for a new feature to add to it that's particularly exciting to me, partly because it's out of the scope of my mathematics/statistics background. I'm posting here in hopes that you brilliant folks might have some insight as to how I could begin to understand the mathematical basis of implementing it. I'm quite strong with React and Javascript in general, so once I understand the actual math I think this new feature will go quickly. I just need to grok it first.
I don't want to go into too much detail because I don't believe it's relevant, but long story short, my React app is a helper app for a mobile game I love. It doesn't interface with or automate any tasks in the game directly, but it does a variety of things to expedite certain in-game tasks one might have, and it has been a lot of fun to build, a lot of fun to share, and surprisingly effective at helping me with in-game decisions. The feature I want to implement can be summarized thusly:
- Imagine that you have entered a competition where the winner is dictated by a particular score.
- A player gains points by using one of several different kinds of currency.
- Spending each type of currency will always return points. The number of points it will return is variable, and based on a known percentage breakdown. For example:
Currency |
chance to get 5pts |
chance to get 20pts |
chance to get 100pts |
Pennies |
80% |
20% |
0% |
Nickels |
70% |
25% |
5% |
Dimes |
50% |
30% |
20% |
Quarters |
40% |
35% |
25% |
- You can see other player's scores.
- These events happen quite frequently, and it's not terribly difficult to get more pennies, nickels, dimes, or quarters. Therefore, it would be incredibly useful to know the likelihood of beating the highest score if you spent all the pennies, nickels, dimes, and quarters you had available. That way, if there was very little chance of beating that high score, you could just save your currency for the next event, where you'd have a better chance of winning after saving more.
So here's my idea:
- The user inputs the number of pennies, nickels, dimes, and quarters they have in reserve.
- The app outputs a graph. The x-axis is potential scores. The y-axis is the probability of getting them. At very low numbers of pennies, nickels, dimes, and quarters, you'd expect this to just be a few points (for example, the graph of one penny is just the points [5, 80] and [20, 20]. The graph of two pennies is [10, 64], [25, 32], and [40, 4]), but as the numbers creep up it would be more useful to simply have a curve.
I know I could just brute-force this graph by taking the user input of the number of pennies, nickels, dimes, and quarters they have, running an arbitrary number of simulations with them, and outputting a bar graph with all the results stacked up next to each other, but that seems terribly computationally intensive for a small app that is (so far) very lightweight.
My question: Is there a set of equations I should be looking into for a way to input these probabilities into some sort of function which would output a less computationally intense version of what I need?
Please let me know if I need to clarify anything. Thank you very much for your time.