1

Suppose I have an integer, $m$, and another integer, $n$, then is there a way of working out how many numbers of length $n$ exist such that the sum of their individual digits is $m$?

Another way of thinking of this is how many ways are there of placing $m$ balls in a row of n buckets such that the first bucket is not empty and no bucket has more than $9$ balls.

Is there an explicit function that takes in the arguements $m$ and $n$ and outputs the answer or will an algorithm have to be implemented?

Thanks in advance

mucciolo
  • 2,950
John Doe
  • 137
  • You're asking for the number of solutions of $x_1+x_2+\cdots+x_n=m$ subject to $0\le x_i\le9$ (well, it's a little more complicated than that, if you don't allow leading zeros, but that can be taken care of). That kind of question has been asked and answered here dozens of times. Have a look at the Related questions, or do a little search through the site. – Gerry Myerson Nov 19 '17 at 23:48
  • What do I search to get to the answers, sorry I'm new to the site. – John Doe Nov 19 '17 at 23:50
  • Well, first look at those Related questions that appear on this page. Then maybe type something like, numbers of given length with given digit sum site:math.stackexchange.com into Google. – Gerry Myerson Nov 19 '17 at 23:54
  • Sorry I can't find anything, could you post a link please. I'm sorry if this is frustrating for you. – John Doe Nov 19 '17 at 23:59
  • https://math.stackexchange.com/questions/388997/how-many-numbers-from-1-to-99999-have-a-digit-sum-of-8, https://math.stackexchange.com/questions/1432294/counting-4-digits-numbers-whose-digits-sum-is-9, https://math.stackexchange.com/questions/1670956/how-many-ways-to-put-balls-in-buckets, https://math.stackexchange.com/questions/1959224/how-many-numbers-below-n-have-equal-digit-sum, https://math.stackexchange.com/questions/2000556/put-n-identical-balls-into-m-different-buckets-each-bucket-has-at-least-one should get you started. – Gerry Myerson Nov 20 '17 at 00:02
  • Thank you very much for the help. – John Doe Nov 20 '17 at 00:03
  • https://math.stackexchange.com/questions/1894412/how-many-positive-integers-106-have-sum-of-digits-equal-to-19, https://math.stackexchange.com/questions/653825/determine-the-number-of-positive-integer-x-where-x-9-999-999-and-the-sum-of-th – Gerry Myerson Nov 20 '17 at 00:10
  • Might as well do it in an arbitrary base. – marty cohen Nov 20 '17 at 00:43

0 Answers0