On my next program, I need a function I am unable to visualize, so I can not do it.
It is a poker game. It knows how many chips you have of each value, and should pick chips to get the desired value.
I have a type like this:
type
value1
quant1
value2
quant2
value3
quant3
value4
quant4
value5
quant5
endtype
Value can be any value, from 1 to 1000, quant is how many chips I have of this value.
Now I want to know how many chips of any value should I take to score 1000 (or any value) points.
They should be in ratio 3:2:1, or 4:3:2:1 or 5:4:3:2:1.
Do I explain myself?
I could let it to the humans to choose chips, but it should better is my program says: (20x5)+(12x25)+(6x100)=1000
Maybe I don't under stand what you're asking, but do you want the most efficient way to distribute 1000 coils using the money you have?
Something like this:
LOCAL amount% = 1000
LOCAL qty%=0
// Check largest coin
qty = INTEGER(amount / value5)
qty = MIN(qty, quant5)
DEC amount, (qty * value5)
// Check next largest coin
qty = INTEGER(amount / value4)
qty = MIN(qty, quant4)
DEC amount, (qty * value4)
... check the rest
// Check smallest coin
qty = INTEGER(amount / value1)
qty = MIN(qty, quant1)
DEC amount, (qty * value1)
//any 'amount' remaining means you didn't have the proper coins to distribute.
You give me some ideas for start working...