[Question]
  [
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:
1. The total value of the coins is \$x\$ cents.
2. You can use those same coins to make every number of cents less than \$x\$.
### Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged '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 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
```
  
[Answer]
# JavaScript (ES6), 57 bytes
A significantly shorter version suggested by [@tsh](https://codegolf.stackexchange.com/users/44718/tsh), who managed to get rid of the edge case \$n<9\$.
Returns an array of 4 integers in reverse order (quarters to pennies).
```
n=>[z=(n-=x=(n-4)%5+4)/25-.7|0,(n=n/5-5*z-1)/2|0,n%2+1,x]
```
[Try it online!](https://tio.run/##TdRNbtNQGIXhuVdxVamyL2kc/8YJyGVUBgxg0GHpIEqc4iq6Lnao2gI7QOqEIeyD9bABlhC@45vziaiKnjpx3@j2KLer@9Ww7tu7/dR1m@awrQ@uPr96qiM3rR/wXNjTclLYWVZO4@prcha52s3KafniaZrKVbniTrNJevZwfeibT5/bvonC7RDauG9Wmzftrrl8dOsosfG@u9z3rbuJbDzc7dp9dPLBndh42/UXq/XHaDD1ufkSGHNl3Jnpm8Fcm9oMx/fOzGRmX8mrTi5OHLTu3NDtmnjX3UTu/79@t9pcuE1UWDMxby/fv4uH8ZV2@xhtI2dxOTTyMzHj7/JB75t@aOTO2651URhaU9fjJ3htwj8/f/z9/Ryal8Jf30Nrg2/2kJnxkSVJEuTeOVx4F3DpXcJz7zlceVfwwnsBL4/3puI08feOTv29o324Gu3Di9E@XGSwD5ejfXg@2oer0T68GL08dtMkyNiF2YXZhdmF2YXZhdmF2YXZhdnN5AzZhdmF2YXZhdmF2YXZhdmF2YXZzeX/xS7MLswuzC7MLswuzC7MLswuvORZpUGZ8KzEKc9KnPGsxDnPSlzwrMQlz0o851mJK56VeMGzErMrnrMLswuzC7MLs5uL2YXZhdmF2YXZFVfswuzC7MLswrqrLKh0V2LdlVh3JdZdiXVXWbDQXYl1V2LdlVh3JdZdiXVXYt2VWHcl1l2JdVdZsNRdiXVXYt2VWHcl1l2JdVdi3ZVYdyXWXYl1V7l8byTHs8r/AQ "JavaScript (Node.js) – Try It Online")
---
# Original version, 73 bytes
Returns an array of 4 integers.
```
n=>n<9?[n,0,0,0]:[x=4-~n%5,y=(z=n/25-.96|0)+(n-=x)/5&1||2,n/5-y-z*5>>1,z]
```
[Try it online!](https://tio.run/##TdRNbtNQFIbhuVdxVQnsSxLH/z8Fp6MyYACDDEMGUeIUV9F1sANqQssKkJgwhH2wHjbAEsI5vvmOaDt4mtR9pdNPvV99XvXrrtkfJqbd1OdtdTbVzLwqbxZmHPDn8nrxUCWTr@ZZOj5W3qky0yid@GX2GOiRZybVg56mz8PHx2hspunkODm9SGezcHxanrv646emqz1327va7@rV5nWzq@dHs/YC7R/a@aFrzJ2n/X6/aw7e1Xtzpf1t292u1h@8XlUz9cVRaqHMWHV1r5aqUv3lZ6dqNNUv6V1DL44Ma92avt3V/q6988z/v32/2tyajZdoNVJv5u/e@v3wTrM9elvPaH7ZVfQ1UsP3/n3bGM91taqqoXuj3D8/f/z9/d1V18Rf31ytnSd9jtTwEQVB4MTWMTuxTtipdcrOrDN2bp2zC@uCXV6eDclhYJ8dHNpnB9twPtiGi8E2nERsG04H23A22IbzwTZcDC4v3TBwInTZ6LLRZaPLRpeNLhtdNrpsdNnoRnRDdNnostFlo8tGl40uG102umx02ejG9PdCl40uG102umx02eiy0WWjy0aXXeJWoZMGuBU5xK3IEW5FjnErcoJbkVPcipzhVuQctyIXuBUZXXKGLhtdNrpsdNnoxmR02eiy0WWjy0aXnKPLRpeNLhtdtuwqcnLZFVl2RZZdkWVXZNlV5BSyK7Lsiiy7IsuuyLIrsuyKLLsiy67Isiuy7CpyStkVWXZFll2RZVdk2RVZdkWWXZFlV2TZFVl2FdP/jeByq/gf "JavaScript (Node.js) – Try It Online")
[Answer]
# Excel, 106 bytes
```
=IF(A1<9,A1*1000,LET(p,MOD(A1+1,5)+4,b,(A1-p)/5-1,q,(b>2)*INT((b-3)/5),c,b-5*q,p&(MOD(c,2)+1)&INT(c/2)&q))
```
[Answer]
## JavaScript (ES6), ~~47~~ ~~45~~ 44 bytes
```
f=
n=>[25,10,5,1].map(v=>(n-=v*=c=-~n/v-1|0,c))
```
```
<input type=number min=2 max=100 oninput=o.textContent=f(this.value)><pre id=o>
```
Port of my latest Charcoal answer, so outputs in reverse order.
[Answer]
# [Jelly (cairdcoinheringaahing's fork)](https://github.com/cairdcoinheringaahing/jellylanguage), ~~23~~ 19 bytes
```
ŒṗŒP§ḟ@ɗƥRḟƥ“¢¦½ı‘Ṫ
```
Extremely inefficient, and probably also bad in terms of golf. The highest number I could test it on is 18.
Outputs a list of the needed coins in ascending order.
The naive conversion to Jelly would be +2 bytes. You can [Try it online!](https://tio.run/##y0rNyan8///opIc7px@dFHBo@cMd8x1OTj88AUgHATGY8ahhzqFFh5Yd2ntk46OGGQ93rvr//7@hAQA "Jelly – Try It Online")
*-4 bytes by changing the output format*
## Explanation
```
ŒṗŒP§ḟ@ɗƥRḟƥ“¢¦½ı‘Ṫ   Main monadic link
Œṗ                    Integer partitions, sorted from longest to shortest
        ƥ             Keep those where the result is empty:
       ɗ              (
  ŒP                    Power set
    §                   Sum each sublist
     ḟ@                 Remove the resulting numbers
         R                from the range [1..input]
       ɗ              )
           ƥ          Keep those where the result is empty:
          ḟ             Filter out
            “¢¦½ı‘        [1,5,10,25]
                  Ṫ   Tail (last item)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~90~~ 87 bytes
```
MinimalBy[Length@Expand@Exp[Log[1+$^d].#]>#.d&&#&/@FrobeniusSolve[d={1,5,10,25},#],Tr]&
```
[Try it online!](https://tio.run/##FcXBCsIgGADgh/nDS7Y02HHDBXVaENRNDP7SbcLUMItGtFc3@i6fwzQYh8neMHdVPlhvHY7bSbbG92kQu/cdvf4n29BLvlxctCpA1VBoQoCsxT6Gq/H2@TiF8WWkrj6clpQzuim/FBQ9R0XyMVqfJKzqToAicxMjTjNnLP8A "Wolfram Language (Mathematica) – Try It Online")
```
FrobeniusSolve[d={1,5,10,25},#]     (* Find nonnegative integer vectors s where {1,5,10,25}.s==x. *)
Length@Expand@                      (* If the number of terms in the expansion of *)
              Exp[Log[1+$^d].s]     (*   (1+$)^s1(1+$^5)^s2(1+$^10)^s3(1+$^25)^s4 *)
 >#.d&&#&/@ %                       (*  for each s is not greater than x (=x+1), discard it. *)
MinimalBy[ % ,Tr]&                  (* Select the s with the least sum. *)
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~80~~ 71 bytes
```
.+
$*
(1{25}(?=1{24}))*(1{10}(?=1{9}))*(1{5}(?=1{4}))*(1+)
$.4$#3$#2$#1
```
[Try it online!](https://tio.run/##K0otycxL/K@nzaWidWgbF5eKXgKEw6VhWG1kWqthbwukTWo1NbWAAoYGEAFLKB8qD5XW1gRqN1FRNlZRNlJRNvyfmxCnYW9jq6EHNFkTJKlsqMBl5Jjw39DAAAA "Retina 0.8.2 – Try It Online") Link includes test suite that automatically generates numbered results ranging from `2` to the input value. Explanation:
```
.+
$*
```
Convert to unary.
```
(1{25}(?=1{24}))*
```
Match quarters, but leaving at least 24 cents.
```
(1{10}(?=1{9}))*
```
Match dimes, but leaving at least 9 cents.
```
(1{5}(?=1{4}))*
```
Match nickels, but leaving at least 4 cents.
```
(1+)
```
Match the remaining cents.
```
$.4$#3$#2$#1
```
Output the remaining cents, plus the number of nickels, dimes and quarters.
38 bytes if outputting a list of coin values is acceptable:
```
.+
$*
M!`1(1{24}|1{9}|1{4}|)(?=\1)
%`1
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRYvLVzHBUMOw2siktsaw2hJEAFmaGva2MYaaXKoJhv//GxoYAAA "Retina 0.8.2 – Try It Online") No test suite yet. Explanation:
```
.+
$*
```
Convert to unary.
```
M!`1(1{24}|1{9}|1{4}|)(?=\1)
```
Try all coin values in descending order. For each coin value, ensure that there are enough cents left for one less than that value.
```
%`1
```
Convert to decimal.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 98 bytes
```
Counts@Join[h={1,5,10,25},FirstCase[IntegerPartitions[#,#,h],s_/;Tr[1^Union[Tr/@Subsets@s]]>#]]-1&
```
[Try it online!](https://tio.run/##DcyxCsIwEADQXxECTidpip2kEigUdCpapxAlSkgy9AK56yR@e@z6hrc4jn5xnD6uhr4OeUUmfc0JTey/CjpQDbTdD8ZUiAdH3lyQffBlcoUTp4xkBAiIFuglT3Mx6vnAjc1cpL6vb/JbSNaehbUHta9TScg7qYPUN4fBmxaOja31Dw "Wolfram Language (Mathematica) – Try It Online")
-13 bytes from @att
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 23 bytes
Quite inefficient, TIO only reaches 15.
```
~+{1|5|10|25}ᵐ.&⟦~{⊇+}ᵛ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pf/ahl6qOmpmobQwNDtdrqciUFXTsFpXK1R20bHjW1PNy24NDOjIe7Omtrgcz/ddrVhjWmNYYGNUamtQ@3TtBTezR/WV31o652bSB39v//AA "Brachylog – Try It Online")
```
~+{1|5|10|25}ᵐ.&⟦~{⊇+}ᵛ
~+                         A list of numbers (which sum is the input)
  {1|5|10|25}ᵐ             where each number is 1, 5, 10, or 25
              .            is the output.
               &⟦          For [0,1,…,N]:
                 ~{⊇+}ᵛ    every element is the sum of a subset of the output.
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~61~~ ~~51~~ ~~30~~ 29 bytes
```
ＮθＦ⟦²⁵χ⁵¦¹⟧«≔÷↔⁻ι⊕θιηＩη≧⁻×ιηθ
```
[Try it online!](https://tio.run/##Tc69DoIwFAXgGZ6i421SEzBhYiK6MGCMcTMOFSq9CVywPyzGZ69FFoeznOR8Oa2Wpp3kEEJNs3cnPz6UgRcv0@dkGNz2hWB5Jlhx5@ydJpW12BPU5I64YKegethp8E5Bg@QtoGA1tUaNipzqosO5YBijo5icDZKDg7QONF@LRs6beMFeu80Q7Iqj@lE6Dtcrn/RvGc0yhDzLwm4Zvg "Charcoal – Try It Online") Link is to verbose version of code. Edit: Reversed the order in which coins are printed to save bytes. Explanation:
```
Ｎθ
```
Input `x`.
```
Ｆ⟦²⁵χ⁵¦¹⟧«
```
Loop over all the denominations in descending order. (Charcoal's predefined `c` variable for `10` conveniently avoids two of the separators here.)
```
≔÷↔⁻ι⊕θιη
```
Find how many coins I can use. Unless the original input was less, we need to be able to form an amount one less than this coin's value, so we take the absolute difference from this value (which handles inputs less than the value of the coin) before integer dividing by the coin's value.
```
Ｉη
```
Print that number.
```
≧⁻×ιηθ
```
Subtract the value of the coins.
]