- There are ten boxes containing 4, 8, 27, 31, 34, 35, 44, 45, 51, and 59 balls of either red, or blue, or green in color.
- Some boxes contain only red balls, some boxes contain only blue balls, and remaining boxes contain only green balls.
- None of the boxes contain balls having more than one color.
One salesman sold
only one box out of them and he declared, "I have the same number of red, blue, and green balls left over."
Which box is sold out?
tl;dr: Two possible boxes were sold, the one with 59 or the one with 8; and if it was the 8, there are two partitions of the remaining boxes that work.
The box counts are [4, 8, 27, 31, 34, 35, 44, 45, 51, 59], the sum of which is 338 which is 2mod3.
Therefore the sold box must also contain 2mod3 so that the remainder boxes have a chance of being divided into 3 equal counts.
So [8, 35, 44, 59] are the candidates for being the sold box.
And then the sum of each color will be, in order: [110.0, 101.0, 98.0, 93.0]
For each candidate we have to find out if, for example
[4, 27, 31, 34, 35, 44, 45, 51, 59] can be partitioned into 3 subsets each of which sums to 110.
We can subdivide the original set according to mod3 value:
0mod3: [27, 45, 51]
1mod3: [4, 31, 34]
2mod3: [8, 35, 44, 59]
So no matter which 2mod3 candidate is chosen, the remaining 9 boxes will include 3 of each mod group.
If 59 is sold, we need the sums to be 93 which is 0mod3. So a color group will likely be one from each mod group to be 0mod3. Example: 51+34+8 = 93 45+4+44 = 93 27+31+35 = 93 done and done And if the answer is unique, this must be it.
A computer search shows the following ways of partitioning the remaining 9 boxes into 3 groups such that the total balls in each group will be equal.
Case 1. Box 59 Sold: (4, 44, 45) (8, 34, 51) (27, 31, 35) each sums to 93
Case 2. Box 8 Sold: (51, 59) (31, 35, 44) (4, 27, 34, 45) each sums to 110
Case 3. Box 8 Sold: (51, 59) (31, 34, 45) (4, 27, 35, 44) each sums to 110
---------- code ----------
from itertools import combinations
myList=([4, 8, 27, 31, 34, 35, 44, 45, 51, 59])
for e in myList:
shList = myList[:]
shList.remove(e)
target = sum(shList)/3
if target%1 != 0:
continue
target = int(target)
print('\n',e, shList,target)
for i in range(2,6):
for comb in combinations(shList,i):
if sum(comb) == target:
print(e, target, comb)
|
Posted by Larry
on 2022-04-29 16:23:40 |