This seems sort of complex so I'll do my best to be as clear as possible.The particular function I'm looking for dynamically creates a money spent | money won chart for a game of gambling.
I have a lottery of sorts that the user can bet on. There are 6 items the user can buy which each have 6 prizes:
These can be put into objects or arrays.
var prices = [5,10,28,50,56,280]
.
var possibleWins = [40,80,250,400,500,2500]
I'm trying to create a chart that calculates how much money you would have to spend on each particular item per game to guarantee you gain money - for 300 games out.
So here is an example of how the chart should start off:
investment = max possible winnings + total spent( which is negative )
The 2nd row is assuming the first game already happened and lost. And so on.
The idea is to start with the smallest item but give up once it can no longer get you positive even if you win. This is why on row 9 we switch to the rock. ( our investment is at 0 and if we play a twig again, the most we can win is 40. So even if we did win, we would actually have lost 5 overall. )
Also worth pointing out is that if you win on 1 item; you win on all items for that particular game. So you get all prizes combined.
I've been working on this for a few days now and some of these related questions have my initial attempts ( but I honestly have no idea ):
How to find the lowest possible combination of keys within an array
Counter that generates the lowest sum from a combination of indexes above the previous value
Add an arrays keys to themselves until exceeding a limit?
EDIT: At least 1 item(s) must be bought every game and games cannot be skipped