You are here:

Advanced Math/combinations of numbers that sum to a given total

Advertisement


Question
QUESTION: I'm developing some Killer Sudoku software and have come up with a requirement to find out how many combinations of the numbers 1 to 9 exist that sum to a given total, with no repetition of numbers allowed in any one combination, and with a specified number of digits in a combination.
i.e. find how many sets of N different digits (where N must be 1 to 9) add up to a total of T.

So if e.g. N=3 and T=8 then there are 2 combinations:
1,2,5
1,3,4

and if N=2 and T=13 then there are 3 combinations:
4,9
5,8
6,7

I have worked out that the total number of N digit combinations (regardless of total sum) is 9 choose N, and that the distribution of totals over this range appears to produce a bell curve, similar to a normal distribution.

I really need a formula to return the number of combinations as a function of N and T - ideally it could be extended to apply not just to a set of digits 1 to 9, but any sized set of digits 1 to S, where S is a square.
i.e. a function of N, T and S.

ANSWER: Also, note that the reason at 4 there are three choices is because we also have to worry about which ones a 2: 1,1,2, 1,2,1, or 2,1,1.
At 5, we could have a 1,1,3 in 3 orders and a 1,2,2 in 3 orders, for a total of 6 choices.

If the number of occurences needs to be cut down in these cases, note that if you have a,a,b, there are 3 choices and a,b,c there are  6 choices.

---------- FOLLOW-UP ----------

QUESTION: It looks like there might be some missing text from the start of your answer...

I also mentioned that there is no repetition of numbers allowed in any one combination, so 1,1,2 would be invalid, for example.
I take your point that e.g. 1,2,5 is equivalent to 1,5,2; 2,1,5; 2,5,1; 5,1,2 and 5,2,1 - it doesn't really matter to me if (N=3, T=8) returns 2 or 6 as I can work with either result.

So - is there a way of arriving at a formula for the number of combinations ?


Answer
The first response was apparently wrong since I allowed duplicates to occur.  I had tried to insert a spreadsheet before the answer you saw.

The best way I found to do this was to still use a spreadsheet to find the sums.  I implemented a technique for counting and put it in the first three columns.  I then sorted for duplicates and eliminated them.  At that point I found the sums and has the spreadsheet do the counting.  I divided the totals by 6, giving
1,1,2,3,4,5,7,7,8,8,8,7,7,5,4,3,2,1,1  Note that when the sum gets close to either end of a number that can come up, the number gets a little different since no duplicates are allowed.  Note that 1 and 7 occur twice, 6 doesn't occur, and 8 occurs three times in the middle.

The numbers I gave mean that there was 1 way to get a sum of 6, 1 way to get a some of 7, 2 ways to get a some of 8, 3 ways to get a some of 9, 4 ways to get a sum of 10, etc.   Note that the 8's are for 14, 15, and 16.

If you need more details on the spreadsheet, ask for them.  It did take several minutes to do it.  Of course, it probably took me longer to write this letter, but computing the spreadsheet took a lot more in depth thought.

Advanced Math

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scott A Wilson

Expertise

I can answer any question in general math, arithetic, discret math, algebra, box problems, geometry, filling a tank with water, trigonometry, pre-calculus, linear algebra, complex mathematics, probability, statistics, and most of anything else that relates to math. I can even tell you it takes me over 2,000 steps to go a mile, but is that relevant?

Experience

Experience in the area; I have tutored people in the above areas of mathematics for almost two years in AllExperts.com. I have tutored people here and there in mathematics since before I received a BS degree almost 25 years ago. In just two more years, I received an MS degree as well, but more on that later. I tutored at OSU in the math center for all six years I was there. Most students offering assistance were juniors, seniors, or graduate students. I was allowed to tutor as a freshman. I tutored at Mathnasium for well over a year. I worked at The Boeing Company for over 5 years. I received an MS degreee in Mathematics from Oregon State Univeristy. The classes I took were over 100 hours of upper division credits in mathematical courses such as calculus, statistics, probabilty, linear algrebra, powers, linear regression, matrices, and more. I graduated with honors in both my BS and MS degrees. Past/Present Clients: College Students at Oregon State University, various math people since college, over 7,500 people on the PC from the US and rest the world.

Publications
My master's paper was published in the OSU journal. The subject of it was Numerical Analysis used in shock waves and rarefaction fans. It dealt with discontinuities that arose over time. They were solved using the Leap Frog method. That method was used and improvements of it were shown. The improvements were by Enquist-Osher, Godunov, and Lax-Wendroff.

Education/Credentials
Master of Science at OSU with high honors in mathematics. Bachelor of Science at OSU with high honors in mathematical sciences. This degree involved mathematics, statistics, and computer science. I also took sophmore level physics and chemistry while I was attending college. On the side I took raquetball, but that's still not relevant.

Awards and Honors
I earned high honors in both my BS degree and MS degree from Oregon State. I was in near the top in most of my classes. In several classes in mathematics, I was first. In a class of over 100 students, I was always one of the first ones to complete the test. I graduated with well over 50 credits in upper division mathematics.

Past/Present Clients
My clients have been students at OSU, people nearby, friends with math questions, and several people every day on the PC, and you're probably make one more.

©2012 About.com, a part of The New York Times Company. All rights reserved.