In Golfenhagen, The people are allowed, and encouraged, to melt down old coins for scrap metal, if the smelter can make a profit off of it. There are 5 coins that make the Golfenhagen mint. The half-penny(0.5)(H), the penny(1)(P), the tea (5)(T), the flag (10)(F), and the driver (25)(D). Golfenhagen also mints bills, in the form of 100(O), 500(E), 1000(N), and 2500(Y). Recently, the price of metals has plumetted to an all time low, and so everybody is trying to give their coins away, as they are worth less than the bills.
A humble software engineer decides to write a program that will guarantee that those who pay with cash will always get at least 9 coins back on any purchase whose net difference is bigger than 3 cents.
Your challenge:
Take on the role of developer, and write a program that takes one input (the net difference of the money handed out and the purchase total) and outputs the correct change.
You must:
- Make your program put out a nominal of 9 coins with any decimal, except where the difference is less than 5 cents (5).
- Make your program output a diverse set of coins, all coins MUST be able to be outputted by your program. no giving change in exclusively in halfcents.
- Use the dollar bills where applicable.
- This is a golf, the shortest code wins
Examples:
301
OODDDTTTTTP
This is a valid output. There are two dollars ("OO"), and 9 coins ("DDDTTTTTP ").
5693
2Y1E1O2D3F2T3P
This is also valid output, as it specifies the currency type and quantities, and has 10 coins.
412
OOOODPP
This is not valid output, as it only uses 3 coins.
20
10P20H
This is not valid, see the second rule
Code example of a change counter for the least change possible. (as requested per cold golf)
package lookup;
public class Main {
static void main(String[]s) {
int changeincents = 53;
int quartercount = 0;
int dimecount = 0;
int nickelcount = 0;
int pennycount = 0;
while(changeincents >= 25){//value of a quarter
quartercount++;
changeincents-=25;
}
while(changeincents >= 10){
dimecount++;
changeincents-=10;
}
while(changeincents >= 5){
nickelcount++;
changeincents-=5;
}
while(changeincents >= 1){
pennycount++;
changeincents--;
}
}
}
Good luck!
Use the dollar bills where applicable
How will you ensure this rule is followed? Is there a way to calculate that using dollar bills is better in a specific situation? \$\endgroup\$