You have 8 batteries, and you know 4 are "good" and the other 4 are "bad."
You have a device that takes 6 batteries, but only 4 need to be "good" for it to work. You can test your device by picking 6 of the batteries and trying to turn the device on, but otherwise there is no way of checking if the batteries are good.
In the worst-case scenario, how many tests do you need so you know of a particular set of batteries which will get your device working?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This doesn’t quite prove that 5 tests are insufficient.
Log in to reply
Log in to reply
Yeah, my first guess was 4 tests... I don't understand why 6 tests are absolutely necessary.
Log in to reply
@Julien Lerouge – I don't have the skill level to prove it mathematically but If you write down the "tests outcome tree" you'll see that, if you are unlucky and every test ends with the uncertain result, even at the fifth test there's an uncertain, therefore you need another test (which can result in both working or not working device, but now the batteries status is defined).
At step 3, #1 - #2 can still be a good pair, and so can #7 - #8. If these are the four good batteries, or three good and one bad, then switching these around will not make the machine work, and after 4 tries without success you still don't know whether #1, #2, #7, #8 are all good or if one of them is bad. Therefore you need additional tests to find a good set.
Log in to reply
@Jon Ølnes – Oh, I didn't think about it. I missed that, thank you for clarification
It does now!
Maximum of 12 tires gives the greatest possibility. Check this following Consider batteries 12345678 in worst case let two dead batteries are in it. So consider only 4 battery slots with 6 batteries among 4 are working and 2 dead. Let 78 are dead batteries in it. Separate 6 batteries into two half 123 and 456 Try this 1234 1235 1236 If none of them works its sure that atleast one among each half is having one dead battery and two working. Consider 1 or 2 or 3 only one is dead, remove battery one after one and try, remove battery no 1 and try 2345 2346 2356 If this also fails the dead battery must be 2 or 3, replace battery 1 with 2 and try again 1345 1346 1356 If this also fails the dead battery must be 3, replace battery 3 with 2 and try again 2345 2346 2356 We need not find dead battery from 456 becaus there are for sure two working batteries among 456 in between there combinations one will work for sure. So in total 12 combinations can me maximum.
test 1:
scenario A d d d c c c / d c
scenario B d d d d c c / c c
scenario C d d c c c c / d d
if scenario A, changing two batteries needs at most 4 more tests untill the device turns on
if scenario B, changing two batteries needs at most 3 more tests untill device turns on,
ir scenario C, the device is already on
Log in to reply
What are the 4/3 more tests? Do you have a proof that those tests are the "at most"? Can you determine whether you are in situation A or B? This needs more explanation why the answer is only 5.
Non sensible. In the WORST sense situation you need 23 tests to light torch. There are 28 combinations of 6 from 8. 7times8 divided by 1times2. Of these there are 12 of 4+2 and 16 of 3+3. Of the 12, there are six bad and six good. 6 + 16 = 22. Only the 23rd attempt would guarantee light up.
Log in to reply
No. Read my proof, or at least the first three paragraphs, which explains how we can make the torch light after at most 7 tests, if we use the right strategy.
The "worst-case scenario" here does not ask for you to test the batteries inefficiently. It is asking for the largest number of tests that the most efficient strategy would require, which is 7.
Log in to reply
I totally agree with Richards: It would not be the WORST CASE SCENARIO if we apply a "right strategy".
"WORST case scenario" means that it is the baddest case scenario of all bad case scenarios possibles, so a"right strategy" is not allowed.
23 attempts would be the correct answer, because at attempt #24, the device would work.
Log in to reply
@Ricardo Pg – If you are going to be that extreme, the worst case scenario occurs if you don't bother to record what tests you have already conducted, in which case you can go on conducting the same test time and again, and never solve the problem. Forget about 2 3 , and go for ∞ .
@Ricardo Pg – Of course the test assumes you use the best strategy. Otherwise you could simply pick the same pair every time and it would never work.
Why cant you switch 2 batteries between 2 tests?
Only 1 bcs the baby didn't mess them up
Look first you test six batteries at random if it works you're done if not then you know the remaining two batteries are good so you can mark them or remember then take four batteries from the original pile if it works then you’re done if not then you know the remaining pile of two batteries is correct so in three tests you can figure it out
Log in to reply
If the first six don't work, you know that either both the others are good, or that one of them is good. You do not know that both are good.
And hey the Iron can hold six batteries AND YOU COPIED THE ANSWER FROM TED ED https://www.youtube.com/watch?v=BSF9s0gbJ2M&feature=share
Log in to reply
The answer is well-known, but my proof (that six tests are needed, and that five are not sufficient) is much more detailed than the TED talk.
You are a cheater
Log in to reply
It would be much more productive if you read the solution, rather than being abusive.
Number the batteries 1 to 8. As Mark Hennings suggests, split the batteries into a groups: (1,2,3) (4,5,6) (7,8)
Test batteries (4 to 8) plus one battery from the first group -- which will be three tests. If there are three bad batteries in group 1 then the device will work first time. If there are two bad batteries in group 1 then when you use the one good battery the device will work. If there is only one bad battery in group 1 then the device will not work for any of the three tests.
So if the device did not work in any of the first three test we know that there is exactly one bad battery in (1,2,3).
Now test batteries (1 to 3 plus 7,8) plus one battery from the second group -- which will be three tests. If there are three bad batteries in group 2 then the device will work first time. If there are two bad batteries in group 2 then when you use the one good battery the device will work. If there is only one bad battery in group 2 then the device will not work for any of the three tests.
So if the device did not work in any of the second three test we know that there is exactly one bad battery in (1,2,3) and one bad battery in (4,5,6). So the other two bad batteries must be (7,8). We only have to identify a set of batteries that will work - we don't have to run a 7th test to prove it, and we know that using (1 to 6) will work.
While you might be lucky and find a combination that works before you have completed the 6 tests, we were asked to find the worst-case scenario.
You forgot to include the possibility of Group 1 having no bad batteries after the third test, and you will still need 6 tests to prove the device will work in such a situation.
Test 4: Test Group 1 and 3 batteries + any battery from Group 2.
Scenario 1: If there are 3 bad batteries in Group 2, the device will work the first time (because there is 1 bad battery in Group 3).
Scenario 2: If there are 2 bad batteries in Group 2, repeat the test with the other 2 batteries in Group 2 until the device works (which gives a maximum of 6 tests, since you know there are 2 bad batteries in Group 3).
Log in to reply
If group 1 has no bad batteries, then either test 4,5,6 will light up. Since group 2 and 3 has at least 1 good battery, adding the 3 good batteries in group one will cause the iron to work
We are looking for two bad batteries outside the torch. If it doesn’t light, at least one of the pair outside must be good. This is the information you get. We need to collect enough bits of information or exhaust all possibilities, collecting information is normally shorter.
Test 1:If we label the batteries a1 a2 b1 b2 c1 c2 d1 d2. Put in pairs a b and c in the torch. For worst case the torch doesn’t light till the last possible opportunity. No light so d1 and d2 cannot be two bad.
Test 2: Repeat leaving out pair c. No light therefore pair c must have at least one good
Test 3 and 4: Repeat leaving out pair b then pair a. None of the pairs can be 2 bad. Therefore all pairs must all be ‘one bad, one good’.
Test 5: Leave out a1 and b1, still no light a1,b1 can’t be 2 bad.
Test 6: leave out a2 and b2, still no light then a1 and b2 or a2 and b1 must be a pair of bad.
Test 7: leave out a1 and b2, no light, a2 and b1 must both be bad.
This is one more test than needed but you would have done it quicker than working out a shorter method.(best real life solution)
However having done test 3 you also know that there are at least 2 good batteries in the torch from set c and d so set a cannot be two good. Extra info, so either set b is 2 good or all sets are one each. (Test 4.1) a1 b1 left out and (test 5.1)a1 b2 left out , no light, we now know that a1 must be good, therefore a2 must be bad. (Test 6.1)a2 with b1 left out, no light, b2 must be bad. Light will therefore work with a2 and b2 left out. 6 tests, one conclusion.
It should be possible to calculate from the number of bits of information you need where you need to know 2 bits of info (2i) where i is knowing where one bad battery is. Each test gives you I think i/3 as it limits a pair from bad-bad or bad-good or good-good to only 2 of those options, but I will leave that idea to someone else.
the question asks for the number of tests it can be done in 3 tests by using the first 6 then replacing 2 then replacing 2 more
Log in to reply
How about this. The torch is not working so those two spare batteries in your hand are both good or one good and one bad. With two good batteries in hand it's easy. Three attempts of changing pair by pair will do the trick. With mixed pair in hand it's a little bit more complicated but just a little. Three attempts of changing pair by pair with no luck tell you one thing. All three couples in the torch are also mixed pairs so you pull one of those pairs out. With two of mixed pairs in hand you can exchange one battery from the first pair for one battery in the other. That way you'll get one good and one bad pair giving you two more (5 in total) attempts to load in enough good batteries to make the torch work.
Number the batteries 1-8. At any given time, six of the batteries are in the device, but we only need four good batteries to make it work. So to simplify the analysis, choose two of the batteries and just leave them in the device. If one or both are good, we'll find out relatively quickly. If both are bad, so be it - we're looking for "worst-case" scenario anyway.
Now test all possible combinations of the remaining six batteries in groups of four:
1,2,3,4
1,3,4,5
1,4,5,6
2,3,4,5
2,4,5,6
3,4,5,6
We're done: Some combination of these six batteries, plus batteries 7 and 8 always in the device, will make the device work.
I think you took a leap with 'if one or both are good, we'll find out relatively quickly', as the case of just one of a pair being good is the hardest to pick apart. If the good batteries are (1,2,5,7) or (1,2,5,8), for example, none of the listed combinations will light the torch. In these two cases, your tests don't shed light on which of them is the working set, since both are consistent with all six tests failing. There are 15 possible ways to choose two batteries from the remaining six, not 6.
Log in to reply
Yes, multiple leaps, all mis-directed! Thanks...
The testing did not cover the following case:
If the batteries 1245 is working and remaining 3678 are not working then the test fails.
If the batteries 1235 is working and remaining 4678 are not working then the test fails.
If the batteries 1236 is working and remaining 4578 are not working then the test fails.
Log in to reply
You're right, of course. I should have slept on this one before posting...
I'd argue more than 6 tests are possible in the worst possible scenario. Picking at random 6 batteries half of which are duds you proceed to replace each battery with another dud after replacing each battery you know that the remaining battery must be charged and it can take a further 4 tries to replace a dud.
Problem Loading...
Note Loading...
Set Loading...
If we test six batteries at a time, and only get a success when four good batteries are chosen, this is the same as testing an "antitorch" which takes two batteries, and only works when both are bad (since the main torch only works when two bad batteries have been left out).
Interchanging the role of "good" and "bad", this problem is therefore the same as that of a more ordinary torch that uses two batteries, and only works when both are good.
To find a pair of good batteries for this ordinary torch, split the eight batteries into two groups of 3 batteries and one pair of batteries. One of these three groups must contain two or more good batteries. It takes up to 3 tests to determine whether a group of 3 contains a pair of good batteries, and just one test to test the pair. Thus we can find light up the torch after at most 7 tests, and so we will know where a pair of good batteries is after at most 6 tests.
Now let us show that we cannot do this with fewer tests. We shall show that, for any choice of 6 tests, there will be a distribution of the batteries which means that those six tests will not result in a torch that lights up. Unless the torch lights, and we have won, we get no feedback from the tests, and so there is no possibility of a strategy which depends on the outcomes of previous tests. Thus we just need to decide on which selection of batteries to test, and see what happens.
For any set of six tests, let G be the graph defined by having the eight batteries as vertices and with six edges, where an edge exists between two vertices precisely when those two batteries have been tested. Since the number of edges is less than the number of vertices minus one, this graph is not connected. I claim that we can find always find four vertices out of the eight so that no two out of these four have edges between them. If true, this would mean that there are four batteries out of the eight such that no two of them have been tested. This would mean that, if those four batteries were the good ones, then the proposed set of six tests would not find a pair of working batteries.
If the disconnected graph G has four or more components, then we can choose four vertices such that each vertex belongs to a different component, and we are done.
If the disconnected graph G has three components, then the three components can have the following vertex counts: ( 6 , 1 , 1 ) , ( 5 , 2 , 1 ) , ( 4 , 3 , 1 ) , ( 4 , 2 , 2 ) or ( 3 , 3 , 2 ) . In the first case, the 6 -vertex component has 6 < 6 C 2 edges, and so there are two vertices out of the six which do not have an edge between them, If we choose those two vertices, and one vertex from each of the other two components, we obtain four vertices, no two of which have an edge between them. In the second case, the component with 5 vertices has 5 < 5 C 2 vertices, so we can choose two vertices from that component and one each from the other two, to obtain a set of four vertices with the right properties. In the third case the component with 4 vertices has at most 4 = 6 − 2 < 4 C 2 edges, so we can find two unconnected vertices from that component, and one each from the other two, to obtain the desired set of four. Similarly, in the fourth case, the component with 4 vertices contains 4 < 4 C 2 vertices, so we can choose two unconnected vertices from that component and one vertex each from the other two components to obtain the desired set of four vertices. Finally, in the ( 3 , 3 , 2 ) case, one of the components with 3 vertices will contain 2 edges, while the other contains 3 . We can choose two unconnected vertices from the component with 3 vertices and 2 edges, and one vertex each from the other two components, and we are done.
If there are just two components, then the components can have the possible vertex counts: ( 4 , 4 ) , ( 5 , 3 ) , ( 6 , 2 ) and ( 7 , 1 ) . In the first case, the two components both contain 3 < 4 C 2 edges, so we can choose two unconnected vertices from each component, making a set of four vertices with the required properties. In the second case, the components have 4 < 5 C 2 and 2 < 3 C 2 edges each, and so we can choose two unconnected vertices from each component, giving us a set of four vertices as required. In the other two cases, the component with 6 (resp. 7 ) vertices contains 5 (resp. 6 ) edges, and is connected, and hence is a tree. For any n ≥ 6 , the complete graph K n has the property that if its edges are 2 -coloured (so that each of its edges are coloured either red or blue), then it is possible to find a monochromatic subtriangle. We can 2 -colour the graph K 6 (resp. K 7 ) by colouring an edge between two vertices red if the component of G with 6 (resp. 7 ) vertices contains that edge, and colouring that edge blue otherwise. Since the component of G with 6 (resp. 7 ) vertices is a tree, it contains no triangles, and hence the coloured graph K 6 (resp. K 7 ) contains no red triangles, and hence much contain a blue triangle. Thus we can find a trio of vertices in the component of G with 6 (resp. 7 ) vertices such that no two of them are connected by an edge. Add a vertex from the other component, and we are done!
Thus we do indeed need at least 7 tests to light up the torch.