[Question]
  [
A drug comes in 5mg, 2.5mg, and 1mg sized pills. The drug is taken once a day. The total daily dose will be only one of the following (all in mg):
1, 2, 3, ... 20, 22.5, 25, 27.5, 30, 32.5, 35, 37.5, 40, 42.5, 45, 47.5, 50
In words: any whole number less or equal to 20, then at 2.5mg increments up to 50.
Your task is to determine how many pills of each size the patient should take to get to their total dose, minimizing the total number of pills they have to take.
Input: the total daily dose
Output: the respective number of 5mg, 2.5mg, and 1mg the patient needs to take, in any consistent format.
This is code golf. Fewest number of bytes wins.
Examples: (output is number of 1, 2.5, and 5 mg pills)
```
1 => [1, 0, 0]
4 => [4, 0, 0]
7 => [2, 0, 1]
19 => [4, 0, 3]
22.5 => [0, 1, 4]
40 => [0, 0, 8]
```
*Irrelevant: this is based on a true story. The drug is prednisone and I wrote a program to automate the production of a calendar for patients to use to titrate their doses, which is a challenging task for many elderly patients to do safely even if you give them written instructions. This challenge was part of the programming task.*
  
[Answer]
# [R](https://www.r-project.org/), ~~53~~ 38 bytes
```
function(x)c(x%/%5,2*x%%1,(x<20)*x%%5)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jQjNZo0JVX9VUx0irQlXVUEejwsbIQBPENtX8n6ZhqMmVpmECIsxBhKEliDQy0jMFixto/gcA "R – Try It Online")
Output is in the order (5mg, 2.5mg, 1mg).
For the 2.5mg pills:
* if the dose is an integer, we need 0 such pills. Indeed, 1 pill of 2.5 mg would not give an integer, and 2 pills of 2.5 mg can be replaced by a single 5mg pill
* if the dose `x` is not an integer, we need exactly 1 such pill (similar argument), and then we call the function with the integer `x-2.5`.
The number of 5 mg pills is the integer division of the input by 5.
Note that because the input is restricted, the 1 mg pills are never needed when the input is ≥20. If the input is <20, the number of 1mg pills is given by taking the input modulo 5.
[Answer]
# [Python](https://docs.python.org/2/), 27 bytes
```
lambda x:[x//5,x%1*2,x*6%5]
```
[Try it online!](https://tio.run/##HcrBCoJAFIXhfU9xEISSWzrXGSuhXsRcGDEk1Cji4vb00x0XPxw@zvxb31Pg6G@P@Bm@z9cAaTspS0eSm4JJiiZ3ffTTAsEY0BkCE2qCJTjChXAlmEpTMI2mZNRYjfmkH06d06rV7GY2tZmr@naHeRnDCiFkx3tG8Hs5xD8 "Python 2 – Try It Online")
An improvement to [Manish Kundu's Python 3 solution](https://codegolf.stackexchange.com/a/210827/20260).
The new part is `x*6%5` for the last entry. The idea is to take the value mod 5 for whole `x`, but to give 0 for the non-integer doses, which are multiples of 2.5. To do this, we multiply by 6 before reducing mod 5. Because \$ 6 \equiv 1\$ modulo 5, multiplying by 6 leaves integers unchanged mod 5, but it turns multiples of 2.5 into multiples of 5, which then reduce to 0.
In the second entry, `x%1*2` could also be `x*2%2` as an equal-length alternative. This may be useful for porting, if a language's mod operation only works on whole numbers.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-pgae)
```
d5ḞƑƇ;Ø.ṁ3
```
A monadic Link accepting the dosage which yields a list of numbers, `[#5, #1, #2.5]`
**[Try it online!](https://tio.run/##AR8A4P9qZWxsef//ZDXhuJ7GkcaHO8OYLuG5gTP///8yMi41 "Jelly – Try It Online")**
### How?
```
d5ḞƑƇ;Ø.ṁ3 - Link: dosage     e.g. 22.5     OR   23
 5         - five                  5             5
d          - div-mod               [4, 2.5]      [4, 3]
    Ƈ      - filter keep if:
   Ƒ       -   is invariant under:
  Ḟ        -     floor             [4]           [4, 3]
      Ø.   - [0, 1]                [0, 1]        [0, 1]
     ;     - concatenate           [4, 0, 1]     [4, 3, 0, 1]
         3 - three                 3             3
        ṁ  - mould like            [4, 0, 1]     [4, 3, 0]
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 25 bytes
This defines a verb that takes as input the list of pills like `[2, 1, 4]` and outputs the sum of the pills milligrams. As this is Brachylog, we can then give an output like `24.5` an ask for a solution for the input.
```
Ṫℕᵐ<ᵛ⁵⁰;[1.0,2.5,5.0]\×ᵐ+
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@HOVY9apj7cOsHm4dbZjxq3PmrcYB1tqGegY6RnqmOqZxAbc3g6UFb7//@o/0YmeqYA "Brachylog – Try It Online") (Note: you have to give the output as a float, e.g. `20.0`.) Or [try all possible inputs.](https://tio.run/##LY09CgIxEEavsmxhYwyZ/LiK4kV0C7XQQhBsFhEtFhHsbMTCG1jZbBHL9STJReJ8YPHC8OYNWezmy/V@s13pdKjyrDfJ8qpzipd3rOvwuR5Dc0vBv@L5ztM4NM/Wt340JamElk44qcrZ98G7bkp/q4RhLMNb0WcKZsAMGVJ4UBJSQkuICTUhJ/SEA8KFxoXGbxqJLngycAbOwBk4C2fhLJyFc@zK9AM)
### How it works
```
 Ṫℕᵐ<ᵛ⁵⁰;[1.0,2.5,5.0]\×ᵐ+
 Ṫ                          the input is a triplet [A, B, C]
  ℕᵐ                        all elements are >= 0
    <ᵛ⁵⁰                    and less than 50 (just to give the search some bounds)
        ;[1.0,2.5,5.0]      append the list of pill sizes
                      \     transpose: [[A,1.0],[B 2.5],[C,5.0]]
                       ×ᵐ   map multiplication over it
                         +  sum the result
```
Some notes: because Brachylog will try counting the trailing numbers up (`0 0 48, 0 0 49, 0 1 0, 0 1 1, …`), this guarantees that the first hit is also the solution with the fewest pills. `1,2.5,5` is not possible as otherwise the search will skip `A = 0, C = 0` for whatever reason. Also, some day I'll find a better way to constrain numbers in `0 … X` than `ℕᵐ<ᵛX` …
[Answer]
# [Rockstar](https://codewithrockstar.com/), ~~127~~ ~~120~~ ~~118~~ ~~110~~ 100 bytes
Borrowing [Robin's](https://codegolf.stackexchange.com/a/210823/58974) logic.
Output order is `1, 2.5, 5` separated by newlines
```
listen to N
let F be N/5
turn down F
let M be N
turn down M
let M be N-M
say N-M*5-F*5
say M*2
say F
```
[Try it here](https://codewithrockstar.com/online) (Code will need to be pasted in)
```
listen to N       :Read input string into variable N
let F be N/5      :Divide N by 5 and assign to variable 
turn down F       :Floor F
let M be N        :Assign N to variable M
turn down M       :Floor M
let M be N-M      :Reassign N-M to M
say N-M*5-F*5     :Output N-M*5-F*5
say M*2           :Output M*2
say F             :Output F
```
[Answer]
# [J](http://jsoftware.com/), 22 bytes
Returns in pill order `5 2.5 1`, based on [@Robin Ryder's answer](https://codegolf.stackexchange.com/a/210823/95594)
```
<.@%&5,(~:<.),5&|*20>]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/bfQcVNVMdTTqrGz0NHVM1Wq0jAzsYv9rcqUmZ@QraFinaSoZKGhk6hkZaOpoGBloG@mZamXqGRpr/gcA "J – Try It Online")
### How it works
```
<.@%&5,(~:<.),5&|*20>]
                  20>] x greater than 20?
              5&|*     multiply with x mod 5
       (~:<.),         prepend (x != floored x)
<.@%&5,                prepend (divide x by 5 and floor)
```
[Answer]
# Excel, 64 bytes
```
=MOD(A1,5)-2.5*(A1<>INT(A1))&","&1*(A1<>INT(A1))&","&TRUNC(A1/5)
```
Input is in cell `A1`.
Working backwards:  
`TRUNC(A1/5)` gives the max number of 5mg pills by dividing and truncating.  
`1*(A1<>INT(A1))` gives the 2.5mg pill count as `1` if the dose is decimal and `0` if it isn't.  
`MOD(A1,5)-2.5*(A1<>INT(A1))` gives the 1mg pill count by taking whatever's left from dividing by 5 and subtracting 2.5 if the dose is a decimal.
[![Results](https://i.stack.imgur.com/tSoGC.png)](https://i.stack.imgur.com/tSoGC.png)
[Answer]
# [Python 3](https://docs.python.org/3/), ~~68~~ ~~64~~ ~~57~~ ~~51~~ ~~43~~ ~~38~~ ~~36~~ ~~34~~ 32 bytes
```
lambda x:[x//5,x%1*2,(x<20)*x%5]
```
[Try it online!](https://tio.run/##HcrdCoJAEMXx@57iIAirTLk7un1I9SLmhRFLQqmIF9PTb6MXfzj8ONNveY9DGcPtET/d9/nqIHUjReFJUpczGbmyzXJJfRvDOEPQD2gcgQkloSJ4wplwITirKbijpuTUWI35oB9eO62rVKs2q9Y287atd5jmfliMEJL9PSEEI1kW/w "Python 3 – Try It Online")
Outputs in order (5, 2.5, 1).
Explanation: Uses as many 5 mg pills as possible, one pill of 2.5 mg if x % 5 = 2.5, otherwise none, and remaining sum is formed using 1 mg pills.
*-11 bytes thanks to Stef*
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~14~~ ~~12~~ 11 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
5‰`D.ïD≠Š*)
```
Output is in the order `[5, 2.5, 1]`.
[Try it online](https://tio.run/##yy9OTMpM/f/f9FHDhgQXvcPrXR51Lji6QEvz/39DSwA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeV/00cNGxJc9A6vd3nUueDoAi3N/zr/ow11THTMdQwtdYyM9Ex1TAxiAQ).
**Explanation:**
```
5‰           # Divmod the (implicit) input by 5: [input//5, input%5]
  `          # Pop and push both values separated to the stack
   D         # Duplicate the input%5
    .ï       # Check if it's an integer (1 if truthy; 0 if falsey)
      D      # Duplicate that
       ≠     # Check that it's NOT equal to 1 (1 becomes 0; 0 becomes 1)
        Š    # Triple swap the top three values on the stack: a,b,c → c,a,b
         *   # Multiply the top two
          )  # Wrap all three values on the stack into a list
             # (after which it is output implicitly as result) 
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 37 bytes
```
#&@@{2,5,10}~FrobeniusSolve~⌊2#⌋&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X1nNwaHaSMdUx9Cgts6tKD8pNS@ztDg4P6cste5RT5eR8qOebrX/AUWZeSXRyrp2aQ7KsWp1wcmJeXXVXIY6XCY6XOY6XIaWOlxGRnqmQL4BV@1/AA "Wolfram Language (Mathematica) – Try It Online")
Unfortunately, `NumberDecompose[8,{10,5,2}]` is `{0,1,3/2}`, not `{0,0,4}`.
The [documentation for `NumberDecompose`](https://reference.wolfram.com/language/ref/NumberDecompose.html) states that "For integers, `NumberDecompose` returns the last solution found by `FrobeniusSolve`", but this is evidently not the case. [Try it online!](https://tio.run/##y00syUjNTSzJTE78/98lP5oroCgzryTaqELXrtqvNDcptcglNTk/tyC/OBUoqFNtaKBjqmNUG6vjk1hc4uBWlJ@UmpdZWhycn1OWGg2T1TGqiAUq4aqu0DE0qI39/x8A "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# JavaScript (ES6), 31 bytes
Outputs an array in the order 5mg, 2.5mg, 1mg. Essentially the same logic as [@RobinRyder](https://codegolf.stackexchange.com/a/210823/58563).
```
v=>[x=v/5|0,v%1&&1,v-(v%1+x)*5]
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/M1i66wrZM37TGQKdM1VBNzVCnTFcDyNKu0NQyjf2fnJ9XnJ@TqpeTn66RpqGgoGCoqamgr68QbaijYABEsVwYKkygKkxwqjCHqjACqzDEVGFoiWKGMboKIyM9U6gKkAE6CiaYZpgYIFQAkUXsfwA "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 27 bytes
A port of [@ManishKundu's answer](https://codegolf.stackexchange.com/a/210827/58563) suggested by @KevinCruijssen.
```
v=>[v/5|0,v%1*2,(v<20)*v%5]
```
[Try it online!](https://tio.run/##HcrLDoIwEIXhvU8xG8LFEZlCRYMlYeFTIAuC4CWkNUC68t1x6OKkzT/fp7Xt3E3v73LQ5tGvg1qtKmt7lL8ErUeRwMBeRRJG1pPNWoGCmhAEQoqQIUiEE0KOcEa4IFDC4zsxIBbEhNgQI2JFzIidYCdEzBexLd9@KbfUtXSbaxm3zLVsm2syaYrdrooHM93a7hVoUCV0Rs9m7OPRPDnswb8vPj9DoMMwLNY/ "JavaScript (Node.js) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
ＮθＩ⟦÷θ⁵﹪⊗θ²﹪×⁶θ⁵
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05oroCgzr0TDObG4RCPaM6/EJbMsMyVVo1BHwVRTR8E3P6U0J1/DJb80KSc1BaheR8EIIRySmZtarGGmowASN9WM1dS0/v/f2FzP9L9uWQ4A "Charcoal – Try It Online") Port of @xnor's solution, saving 3 bytes over a generic solution such as a port of the other solutions. Explanation:
```
Ｎθ
```
Input the dose.
```
Ｉ⟦
```
Output the result on separate lines.
```
÷θ⁵
```
Integer divide the dose by 5.
```
﹪⊗θ²
```
Modulo the doubled dose by 2.
```
﹪×⁶θ⁵
```
Modulo the sextupled dose by 5.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 17 [bytes](https://github.com/abrudz/SBCS)
```
|⌊0 ¯1 5|.2 1 6×⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT/@f9qhtQvX/mkc9XQYKh9YbKpjW6BkpGCqYHZ7@qHfr/9r/j7oWFWTm5BQDlWk86t1sZKCpY2SgbaRnClKw2dCIK@3QCgWwCgA "APL (Dyalog Unicode) – Try It Online")
```
|∘⌊÷∘5,¯1∘|,5|6∘×
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v@ZRx4xHPV2HtwNpU51D6w2BdI2OaY0ZkD48/X/ao7YJj3r7HnU1H1pv/Kht4qO@qcFBzkAyxMMz@P@jrkUFmTk5xUBFGo96NxsZaOoYGWgb6Zkeng7kGhpxpR1aoQBWAQA "APL (Dyalog Unicode) – Try It Online")
```
3↑0 1,⍨(⊢∩⌊)0 5⊤⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT/@f9qhtQvV/40dtEw0UDHUe9a7QeNS16FHHykc9XZoGCqaPupY86t36v/Y/ULQgMyenGKhc41HvZiMDTR0jA20jPdPD04FcQyOutEMrFMAqAA "APL (Dyalog Unicode) – Try It Online")
First two are the ports of [xnor's Python answer](https://codegolf.stackexchange.com/a/210858/78410) giving `5mg 2.5mg 1mg`, and the last is from [Jonathan Allan's Jelly answer](https://codegolf.stackexchange.com/a/210841/78410) giving `5mg 1mg 2.5mg`. The first and third are full programs, and the second is a tacit function.
### How all these work
```
|⌊0 ¯1 5|.2 1 6×⎕  ⍝ Input: single number x
         .2 1 6×⎕  ⍝ (x/5)(x)(6x)
  0 ¯1 5|          ⍝ (x/5)(x%-1)(6x%5); x%-1==-0.5 if x%1==0.5
|⌊                 ⍝ Floor then abs
|∘⌊÷∘5,¯1∘|,5|6∘×  ⍝ Input: single number x
            5|6∘×  ⍝ 6x%5
       ¯1∘|        ⍝ x%-1
   ÷∘5             ⍝ x/5
|∘⌊   ,    ,       ⍝ Concatenate all and floor then abs
3↑0 1,⍨(⊢∩⌊)0 5⊤⎕  ⍝ Input: single number x
            0 5⊤⎕  ⍝ (x//5)(x%5)
       (⊢∩⌊)       ⍝ Discard non-integers
  0 1,⍨            ⍝ Append two numbers 0 1
3↑                 ⍝ Take 3 from the head
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 16 bytes
```
/Q5*2%Q1*%Q5<Q20
```
[Try it online!](https://tio.run/##K6gsyfj/Xz/QVMtINdBQSzXQ1CbQyOD/fyNzPVMA "Pyth – Try It Online")
Same as my [Python solution](https://codegolf.stackexchange.com/a/210827/77516). Output contains 3 lines: number of 5 mg pills, 2.5 mg pills and 1 mg pills respectively.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 40 bytes
```
^\d+
$*
^(1{5})*(1)*(11.5)*$
$#1 $#3 $#2
```
[Try it online!](https://tio.run/##FcdBCsIwGETh/TuF0AhthJL5kzTtCbyEFAVduHEh7sSzxwTeMHzvx@f5utXjeL7W/XI/4Tz7qG/@TX5Un@Y8eYcbdHBDbLNahRFJZBYKKxsKSMhQRAlltKCCVrRhAbM5Y63SPgZid2x1p0DqTq3uHP4 "Retina 0.8.2 – Try It Online") Link includes test suite. Explanation:
```
^\d+
$*
```
Convert the integer part of the dose to unary.
```
^(1{5})*(1)*(11.5)*$
```
Divmod by 5, then split the remainder into 1s and an optional 2.5 (if the original dose was not an integer).
```
$#1 $#3 $#2
```
Output the numbers of the pills in the order 5s, 2.5s, 1s.
[Answer]
# [Arn](https://github.com/ZippyMagician/Arn), [~~12~~ 11 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn)
Based off of [Manish Kundu](https://codegolf.stackexchange.com/a/210827/90265)'s and [xnor](https://codegolf.stackexchange.com/a/210858/90265)'s answers. Gives `[1mg, 5mg, 2.5mg]`
```
ê═]²*►U¦█–)
```
[Try it!](https://zippymagician.github.io/Arn?code=Wzp2LzU6KyUxXyo2JTU=&input=MQo0CjcKMTkKMjIuNQo0MA==)
# Explained
Unpacked: `[*6%5:v/5:+%1`
```
[ Begin sequence of elements
  *6%5 Perform (_ times 6) mod 5
  :v/5 Floor _ divided by 5
  :+%1 Double _ mod 1
] End sequence, implied
```
Variable `_` is implied. Initialized to STDIN when a program begins.
[Answer]
# [Perl 5](https://www.perl.org/) -pl, 32 bytes
```
$_=join' ',int$_/5,0+/\D/,$_*6%5
```
[Try it online!](https://tio.run/##FcrBCgIhFIXh/XmKFsZAWXqvXp1ZtOsxAlctjMGRaZ4/U/jh8MGp732V1lR6fLZcptOkczlUMqLt1byeRqt0Cef@IDAcPAQBETMWkAURiEEO5EECCqAImkEL2IL5LuBe7Oss3LDrDXsLP@x7w2J/Wz3yVr7tVtc/ "Perl 5 – Try It Online")
[Answer]
# T-SQL, 31 bytes
```
SELECT @%5-@%1*5,@%1*2,str(@)/5
```
**[Try it online](https://data.stackexchange.com/stackoverflow/query/1293422/how-many-of-each-pill-to-take-to-achieve-the-total-daily-dose)**
[Answer]
# [Go](https://golang.org/), 104 bytes
```
import ."math"
func f(x float64)(int,float64,int){return int(x/5),Ceil(x)-Floor(x),int(Min(20/x,1)*x)%5}
```
[Try it online!](https://tio.run/##bY7LCsIwEEXX5itCQJiR2Bet4lpwJ/gLoTQaTJMSUgiUfntNpSvj7tzD5c487TKI9i2eHe2FMoSofrDOUyZ7z5YtZKwX/sWIHE1LJQQqtRX@VCMo4/kWeGScXOdHZ2hkCHmD/NopDQGPN22ti7C24K4MVEUeeImHgPtmXr7L6wOAdCK7eDx7uFjVBiSUiL@qTtU5VeUldVWVNX/2itQ1q5uXDw "Go – Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~72~~ ~~69~~ 67 bytes
```
y;f(float x){printf("%d,%d,%d",(y=x*10)/50,y=y%50==25,!y*(y=x)%5);}
```
[Try it online!](https://tio.run/##HYvBCoQgFEX3fYUJwnth5QguQvwYKYygnCiDHtG3OzVwN4dzbl/3s49jzmQDhPnrEzvxWrcppgBcDPI/LoHcWX0UtkZJciSMck4bWVL1GhQG7Z2fE1v8FBngVbAAHdr1SDtwjvZlrZunK@78Aw "C (clang) – Try It Online")
Saved 1 thanks to @ceilingcat
Saved 2 thanks to @rtpax
Output n#5mg, n#2.5, n#1
]