- Thread starter
- #1

I am writing a basic program using Java. The function is to break up any number the user inputs into smaller values, the catch is that these smaller values have a maximum usage and the overall result has to use the combination with the highest amount of values. I am figuring out the code just fine. I have made a class for the values to define their value, max value and max usage, it is the maths I am struggling with.

For example, the input is 377. I need to break it down into a *maximum* of twenty 1's, twenty 2's and one hundred 5's but my desired result has to be the most long winded, so in this case 17 1s, 10 2s and 68 5's. So I need to be able to figure out the maximum amount of 1s to allow the maximum amount of 2s to ,in turn, allow the maximum amount of 5s. And this needs to work with any number the user inputs.

I would later add higher numbers with set maximum usage and a finally the value of 100 with infinite useage. For now I just need a few equations to work with.

Can anyone shed a little light on a few possible ways of doing this? thanks =)

For example, the input is 377. I need to break it down into a *maximum* of twenty 1's, twenty 2's and one hundred 5's but my desired result has to be the most long winded, so in this case 17 1s, 10 2s and 68 5's. So I need to be able to figure out the maximum amount of 1s to allow the maximum amount of 2s to ,in turn, allow the maximum amount of 5s. And this needs to work with any number the user inputs.

I would later add higher numbers with set maximum usage and a finally the value of 100 with infinite useage. For now I just need a few equations to work with.

Can anyone shed a little light on a few possible ways of doing this? thanks =)

Last edited: