This problem is an extension of what happens to me on a regular basis: I have to have $1.00 in coins and have to be able to give change to somebody. I discovered rather quickly that the ideal coins to have were 3 quarters, 1 dime, 2 nickels, and 5 pennies. This is the smallest number of coins (11 total) that allows me to make any number of cents 1-99.
The Challenge
Write a program that, given an integer input \$x\$ between 2 and 100 (inclusive), outputs the smallest arrangements of coins that does both of the following:
- The total value of the coins is \$x\$ cents.
- You can use those same coins to make every number of cents less than \$x\$.
Rules
- This is code-golf so shortest code (in bytes) wins.
- Standard loopholes are forbidden
- The output can be a list, a four-digit number, or any reasonable representation of the number of coins needed. These coins must be in either ascending or descending order but they do not need to be clearly denoted, only consistently formatted.
- In other words, all of the following are valid:
[1, 2, 3, 4]
[1 2 3 4]
4321
1 2 3 4
1P 2N 3D 4Q
PNNDDDQQQQ
. Simply state somewhere whether your output is listed in ascending or descending order; it must be the same order for all outputs.
- In other words, all of the following are valid:
- In the case that an optimal solution has none of a given coin, your output must contain a "0" (or other similar character, so long as it is used exclusively and consistently for "0"). This rule does not apply if you use the PNDQ or QDNP format.
- The only coins that exist are the penny, nickel, dime, and quarter, being worth 1, 5, 10, and 25 cents respectively.
- An arrangement of coins is considered "smaller" than another if the total number of coins is less; all coins are weighted equally.
Test Cases
x Output (Ascending four-digit number)
2 2000
3 3000
4 4000
5 5000
6 6000
7 7000
8 8000
9 4100
10 5100
11 6100
12 7100
13 8100
14 4200
15 5200
16 6200
17 7200
18 8200
19 4110
20 5110
21 6110
22 7110
23 8110
24 4210
25 5210
26 6210
27 7210
28 8210
29 4120
30 5120
31 6120
32 7120
33 8120
34 4220
35 5220
36 6220
37 7220
38 8220
39 4130
40 5130
41 6130
42 7130
43 8130
44 4230
45 5230
46 6230
47 7230
48 8230
49 4211
50 5211
51 6211
52 7211
53 8211
54 4121
55 5121
56 6121
57 7121
58 8121
59 4221
60 5221
61 6221
62 7221
63 8221
64 4131
65 5131
66 6131
67 7131
68 8131
69 4231
70 5231
71 6231
72 7231
73 8231
74 4212
75 5212
76 6212
77 7212
78 8212
79 4122
80 5122
81 6122
82 7122
83 8122
84 4222
85 5222
86 6222
87 7222
88 8222
89 4132
90 5132
91 6132
92 7132
93 8132
94 4232
95 5232
96 6232
97 7232
98 8232
99 4213
100 5213
n
and an array of denomination values, find the minimal number of coins. \$\endgroup\$