# The coin catastrophe [closed]

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!

## closed as unclear what you're asking by Lynn, Peter Taylor, NoOneIsHere, Blue, Zach GatesAug 28 '16 at 14:31

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• 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? – Buffer Over Read Aug 22 '16 at 18:45
• I don't understand how one option is chosen when there's multiple choices. – xnor Aug 22 '16 at 18:46
• @ColdGolf well, aside from the 9 coins, the consumers typically want the least ammount of change possible. – user56309 Aug 22 '16 at 18:49
• Is there a way to calculate "the least amount of change possible" in a given situation? – Buffer Over Read Aug 22 '16 at 18:52
• I also don’t really understand the question as it’s currently written. AIUI, there is some leeway, and there are multiple valid outputs for each input; is that right? – Lynn Aug 22 '16 at 22:11

## Haskell, 177 165 bytes

Thanks to @Lynn.

f n|n>2504='Y':f(n-2500)|n>1004='N':f(n-1000)|n>504='E':f(n-500)|n>104='O':f(n-100)|n>29='D':f(n-25)|n>14='F':f(n-10)|n>9='T':f(n-5)|n>6='P':f(n-1)|0<1=[1..2*n]>>"H"


In a readable format:

f n
| n > 2504 = "Y" ++ f(n-2500)
| n > 1004 = "N" ++ f(n-1000)
| n > 504 = "E" ++ f(n-500)
| n > 104 = "O" ++ f(n-100)
| n > 29 = "D" ++ f(n-25)
| n > 14 = "F" ++ f(n-10)
| n > 9 = "T" ++ f(n-5)
| n > 6 = "P" ++ f(n-1)
| 0 < 1 = replicate (2*n) 'H'


Just give out the biggest denomination which still leaves more than 5 cents to fill with halfcoins.

• Some tips: replicate(2*n)'H' is [1..2*n]>>"H", and "A"++b is 'A':b. – Lynn Aug 22 '16 at 22:07