A composition of a positive integer $n$ is a way of writing $n$ as the sum of an ordered sequence of strictly positive integers. Any positive integer $n$ has $2^{n - 1}$ distinct compositions.
Compositions of $n$ range in length from one ($n$ on its own) to $n$ ($n$ instances of the number $1$ added together). The number of compositions of $n$ into exactly $k$ parts is the binomial coefficient $\binom{n - 1}{k - 1}$, or $\frac{(n - 1)!}{(k - 1)! × (n - k)!}$.
What I want to find is a formula that gives the number of compositions of $n$ of length $k$ containing only numbers between $1$ and $p$, inclusive, but no higher.
For example, the number $6$ has $2^{6 - 1} = 32$ compositions: one of length $1$, five of length $2$, ten of length $3$, ten of length $4$, five of length $5$, and one of length $6$. If the cutoff value is $p = 3$, that is reduced to $24$ compositions: zero of length $1$, one of length $2$, seven of length $3$, ten of length $4$, five of length $5$, and one of length $6$.
When $\frac{n}{2} ≤ p ≤ n$, I found that the formula $\binom{n - 1}{k - 1} - k × \binom{n - p - 1}{k - 1} = \frac{(n - 1)!}{(k - 1)! × (n - k)!} - k × \frac{(n - p - 1)!}{(k - 1)! × (n - p - k)!}$ works. However, when $1 ≤ p < \frac{n}{2}$, this formula over-counts the compositions to be excluded. This seems to be because the second term counts, for example, how many numbers greater than $p$ are in compositions of length $k$ and not what I want, which is how many compositions of length $k$ contain at least one number greater than $p$. This means that it double-counts compositions that contain two instances of an invalid number, triple-counts compositions that contain three instances, and so on.
Is it possible to find a closed-form (non-recursive, non-infinite) formula that gives the results I want?
For reference, here are the compositions of integers $1$ through $6$, color-coded by length (background color) and highest number (text color):