How do I find out how many different combinations of this set {-1,-2,-3,-4,1,2,3,4} add up to equal 20? The combinations can have repeating numbers ex. one set can be {1,1,1,1,1,-2,3,1}. The size the set is restricted to 8. Thanks!
How to find the number of combinations of a certain set that equals a certain number?
-
0Unless there are restrictions on the size of the set, infinitely many: Find any set that adds to $20$ (e.g. $\{4,4,4,4,4\}$) and add (as many times as you like) one of the many subsets with a sum of $0$. – 2017-01-08
-
0Oh sorry, the limit to the size of the set it 8 – 2017-01-08
-
0Do they have to have size $8$, or is that only an upper bound? – 2017-01-08
-
0I honestly don't even know where to start, I just want to find a quicker way to do it instead of doing everything by hand. – 2017-01-08
-
1They have to have size 8 exactly – 2017-01-08
-
020's a pretty big sum, given the set; it takes a subset of at least size 5 to reach. I don't really think there's a slick approach here. It shouldn't be hard to find/count all the subsets of size $k\ge 5$ containing only positives that sum to $20$; with that, you can see how many ways there are to add elements that sum to $0$ (to bring the subset size up to 8), in each case (there shouldn't be many, and you only need to consider subsets of size 5 or 6 with only positives). So, I'd just use a "messy" analysis by cases. I'd expect maybe two dozen solutions tops (probably less). – 2017-01-08
1 Answers
A simple observation shows that at least 5 of the numbers have to be positive in the combination of 8 numbers, for the sum to have any chance of getting to 20. Now, we can deal this in cases:
Case I:
If exactly five of them are positive integers, then it isn't possible because after putting five 4s and summing upto 20, we can't sum rest of the three negative integers to 0.
Case II:
If exactly six of them are positive integers, then 2 of them are negative integers. Well out of given negative integers, sum of 2 negative integers can either be -2, -3, -4, -5, -6, -7 and -8.
This means that six of our positive integers can sum up to either 22, 23, 24, 25, 26, 27 and 28. So, we have to find the number of ways in which these numbers can be written, using only 1,2,3 or 4, and only six times. So, only 22,23 and 24 are possible in this way.
24 can be expressed as a sum of 1,2,3 and 4 in only one way: 4+4+4+4+4+4 = 24.
23 can be expressed only one way : 3+4+4+4+4+4 = 23
22 can be expressed in two ways : 4+4+4+4+4+2 = 22 = 4+4+4+4+3+3
So in this 2nd case, we have altogether 4 ways of doing it.
Case III: If exactly seven of them are positive integers, then only negative remaining number can be -1,-2,-3 or -4. In this case,seven of them must sum to 21,22,23 and 24.
7 positive numbers can sum up to 21 in two ways: either have seven 3s or have five 3s, one 2 and one 4.
Now you have to find in how many ways can seven numbers from {1,2,3,4} sum up to 22,23 or 24.
Case IV
Now, you can have all 8 numbers positive, in which case you need to determine, how many ways can we write 20 as sum of 8 positive numbers from {1,2,3,4}. This can be determined (rather painstakingly) using the fact that we need at least
-
0In Case II, there is one way to express $24$ as a sum of six positive numbers, but then there are ***two ways*** to express $-4$ as a sum of two negative numbers, so I think "altogether $4$ ways of doing it" is kind of misleading. What is meant by "it"? – 2017-01-08
-
0there are "altogether 4 ways of doing it" as in 4 ways in which case II can be satisfied. – 2017-01-08
-
0But I would interpret "number of ways II can be satisfied" to mean "number of ways to pick $6$ positive and $2$ negative numbers which add up to $20$ and so I get $5$ ways: $$4+4+4+4+4+4-1-3$$ $$4+4+4+4+4+4-2-2$$ $$4+4+4+4+4+3-1-2$$ $$4+4+4+4+4+2-1-1$$ $$4+4+4+4+3+3-1-1$$ You need to express yourself more clearly. – 2017-01-08
-
0@bof Excuse me??? Perhaps a few lesson on talking respectfully might help you.. – 2017-01-08