Problem with batteries

Logic Level 4

We have 8 batteries: 4 good and 4 dead ones. We don't know which is which, as they all look the same. Now, there is a flashlight which will turn on if it's powered by two good batteries. What is the minimum number of tries we need to guarantee that the flashlight turns on?


Clarification: In a try, we place two batteries into the flashlight and see if it works. The flashlight must turn on with the last try.

6 7 8 9 10

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.

6 solutions

Andy Hayes
Jun 21, 2017

Label the batteries A, B, C, D, E, F, G, H.

Try the combinations AB, BC, and AC. In the worst case, those three combinations will fail. This means that there are either 0 or 1 good batteries among A, B, and C. Then there are 3 or 4 good batteries among D, E, F, G, and H.

Now try the combination DE. In the worst case, this combination will fail. This means that there are 0 or 1 good batteries among D and E. Now we know that F, G, and H have at least 2 good batteries.

Try the combinations FG, GH, and FH. Since there are at least 2 good batteries among them, one of these combinations will work. In the worst case, it will be the last combination you try. Thus, it will take 7 \boxed{7} tries in the worst case to get the flashlight to turn on.


This proves that it can be done in 7 tries, but is it possible to do it in fewer tries? Consider that the given solution partitions the batteries into groups of 3, 2, and 3 (checked in that order). In the worst case, this requires ( 3 2 ) + ( 2 2 ) + ( 3 2 ) = 7 \binom{3}{2}+\binom{2}{2}+\binom{3}{2}=7 checks. Now consider how else the batteries could be partitioned.

If one were to check all combinations of a group of 6, then we are guaranteed to turn the flashlight on at least once. However, this would take ( 6 2 ) = 15 \binom{6}{2}=15 tries in the worst case. Likewise, checking all combinations out of a group of 5 would take ( 5 2 ) = 10 \binom{5}{2}=10 tries, and it wouldn't even guarantee that we could turn the flashlight on!

If one were to check a group of 4, then this would require ( 4 2 ) = 6 \binom{4}{2}=6 tries, and it would not guarantee that the flashlight would turn on. Since it would take at least 1 more try to turn the flashlight on, you wouldn't be able to beat the count of 7 in this way. Therefore, batteries should only be checked in groups of 3 or less.

A strategy of checking the batteries in groups of 2 doesn't give nearly enough information to deduce where the good batteries are. If you partition the batteries into 4 groups of 2, and check each group, in the worst case, all 4 tries will fail. Even though you know that there is 1 good battery in each pair, finding the combination of 2 good batteries within 4 batteries would take up to 4 more tries (and would be the same as checking a group of 4).

Thus, the optimal strategy would involve checking batteries in groups of 3. Now suppose you checked two groups of 3. In the worst case, none of the 6 tries would work. You would need 1 more try with the remaining group of two (and in this case, it would be guaranteed to work -- this is another solution). Likewise, checking groups of 2, 3, and 3 (in that order) is another solution (also requiring 7 tries in the worst case).

There's one more solution, but it too requires 7 tries in the worst case. You could check groups of 2, 2, and 3 (in any order). If all 5 of those tries fail, then the last remaining battery must be good. You'd have to check it against one of the groups of 2 (and this would require 2 more tries in the worst case. This is effectively the same as making a group of 3) Thus, the minimum number of tries needed is 7.

You might be thinking of a strategy that involves only checking some of the combinations out of a group. For example, how about a strategy of checking AB, BC, and CD (and ignoring the combinations of AC, AD, and BD)? In the worst case, these tries would all fail, and you would gather that the 4 batteries contain 0, 1, or 2 good batteries. This is no better than simply checking AB and CD! Furthermore, you cannot eliminate the possibility of there being 2 good batteries in the group until you check the remaining 3 combinations.

I think the best we can do is 6. We cannot do 5 or under: indeed, it has to be more than 4 because 4 bad batteries could make the 4 first attemps unworking. Then, it cannot be 5, because it would mean that you would have spotted 2 good batteries after the 4 first tries, therefore you would have spotted 6 batteries among which there are 4 bad batteries. This is not possible. Then it has to be at least 6. If we denote the batteries ABCDEFGH, you can do: AC AD BC BD If none is working, you know for sure there are at least 3 unworking batteries among ABCD Then, you try EF GH, among which one of the combinations has to work because there is only one bad battery among the 4.

Charles Riou - 3 years, 11 months ago

Log in to reply

Ah no sorry, my mistake, it does not work in 6.

Charles Riou - 3 years, 11 months ago

I was thinking 6 at first too, but then realized I missed one. My approach: AB, CD, EF, GH. In most cases, one of these combinations will work. If not, then we know that each of the battery combinations has exactly one good battery and one bad battery. Using that logic, you could take any of those pairs (let's say AB, and CD) and try AC AD BC. One of them would have to work.

Terence Attema - 3 years, 11 months ago

Log in to reply

"One of them would have to work." Not if B and D are the good batteries while A and C are both bad.
As you say, the strategy of pairing off batteries will work most of the time. But the worst-case behavior of this approach is pretty bad. If your first four tests fail, you really don't have much useful information. It will take two more tests just to isolate one bad battery.

Richard Desper - 3 years, 11 months ago

Log in to reply

Oops, yea I missed one case , we'd also have to try BD, so with that strategy it would be 8. I wonder what the optimal strategy is in terms of expected value of number of attempts required.

Terence Attema - 3 years, 11 months ago

I wanted to say, do you really have to try the last couple which you can isolate as working couple. But question says the light needs to be turned on. Next to that; nice solution!

Peter van der Linden - 3 years, 11 months ago

Log in to reply

No, the question ends "....to guarantee that the flashlight will turn on?" You do not have to turn it on, just to prove it WILL turn on, which is done once you have removed 4 duff batteries from the equation.

Geoff Holmes - 3 years, 11 months ago

Isn't the minimum number of tries one try??

Abanoub Victor - 3 years, 11 months ago

Log in to reply

The question requires the minimum number of tries to guarantee that the flashlight will turn on. You can't guarantee that the flashlight will turn on in one try. However, by applying a strategy for checking the batteries, you can guarantee that the flashlight will turn on in somewhere between 1 and 7 tries.

Andy Hayes - 3 years, 11 months ago

Strategy for 4 groups of 2 works! If all fail, then you can never have fail-fail. If you do, that means for the other three groups you have (up to ordering): Dead-alive, dead-alive, alive-alive Dead-dead, alive-alive, alive-alive. Either way, you have alive-alive, which contradicts that all four failed.

Jimbo Juice - 3 years, 11 months ago

Log in to reply

So you know that each pair has one good and one bad battery. What next? This is what I think: without loss of generality, we next test B1 & B3 together. And, worst case, they fail. That only implies that B2 or B4 is good. But which one?
The problem with starting using pairs is that the information you gain just isn't that useful. I believe if you start with this approach, you may need as many as 8 tests to find a pair that works.

Richard Desper - 3 years, 11 months ago

What about this.....

Put the first 6 batteries into 2 lots of 3

If G=Good and B=Bad then the layout of group one will be one of the following:-

a) 3G/0B b) 2G/1B c) 1G/2B d) 0G/3B

In (a) 2 good batteries will be found on try 1; in (b) no more than 3 attempts

In (d) 3B means we have had 3 tries, all failed. However, we now know that at most there is only 1B in group 2. We shall find a good pair in a maximum of 3 tries in this group. Consequently a maximum of 6 tries overall.

In scenario (c), there will be 1, 2 or 3 good batteries in group 2 - if 1 then all 3 tries fail then batteries 7 & 8 must be good (without the need to test) If 2 good batteries then a minimum of 3 tests to find a good pair (6 overall). If 3 good batteries, a pair will be found at the first test.

Never more than 6 tries!! – Geoff Holmes

Geoff Holmes - 3 years, 11 months ago

Log in to reply

If the question was, "What is the minimum number of tries needed to guarantee that a pair of good batteries can be identified?" then you would be correct. However, the question is "What is the minimum number of tries needed to guarantee that the flashlight will turn on?" Even though you can identify the good batteries with 6 tries, you need the 7th try to turn it on.

Andy Hayes - 3 years, 11 months ago

Log in to reply

@Andy Hayes, I disagree.... part of the information given: "4 good and 4 batteries" is a statement of fact, consequently, no need to try to prove the 7th!! It is a given, you must use ALL info given - and take as fact, if it tells you such – Geoff Holmes

Geoff Holmes - 3 years, 11 months ago

The question is how many tries will it take to "guarantee" that the light will turn on. That is 6. The seventh trial is just needed for confirmation. But if you believe the premises of the question are indeed true, then all you need is six tries for you to know that the light will go on for that seventh try. These analyses are correct, but the answer to the question as stated should be six.

David Dorenfeld - 3 years, 11 months ago

Log in to reply

If the question was, "What is the minimum number of tries needed to guarantee that a pair of good batteries can be identified?" then you would be correct. However, the question is "What is the minimum number of tries needed to guarantee that the flashlight will turn on?" Even though you can identify the good batteries with 6 tries, you need the 7th try to turn it on.

Andy Hayes - 3 years, 11 months ago

Log in to reply

No, you can GUARANTEE through logic - the puzzle TELLS you that "4 good batteries" exist. The fact you have ruled 4 bad ones out means you are guaranteeing success (guaranteeing does not mean "see it happen").... Believe the Logic!!?? : )

Geoff Holmes - 3 years, 11 months ago

Log in to reply

@Geoff Holmes The intent of the problem is to turn the flashlight on, and it takes a "try" to turn the flashlight on. However, I can see where you are coming from. I have edited the problem to clarify the intent of the problem.

Andy Hayes - 3 years, 11 months ago

Log in to reply

@Andy Hayes No, no, no.... The intention is to find out "....the minimum number of tries we need to guarantee that the flashlight turns on?" - one doesn't need an actual torch, the puzzle does not say "see the torch on" as, once you have ruled out the negative combinations, you only have positives left - the puzzle may be solved on paper. You are given several FACTS, the FACT that there are FOUR Bad batteries is key. If I am told drinking a bottle of acid will lead to death, I don't have to try it to understand that "Drinking Acid = Death".... I can merely accept it as being true!!

Geoff Holmes - 3 years, 11 months ago

Andy Hayes, I disagree.... part of the information given: "4 good and 4 batteries" is a statement of fact, consequently, no need to try to prove the 7th!! It is a given.

Geoff Holmes - 3 years, 11 months ago
Jason Dyer Staff
Jun 28, 2017

The proof that 6 tests do not suffice can be expressed as a graph theory problem.

Each battery is the vertex of a graph G , G, and the tests are edges in the graph. We will suppose an arbitrary graph with 8 vertices (batteries) and 6 edges (tests).

We are going to attempt a "worst case coloring", in this case coloring dead batteries red. We want to prove we can always color the 4 dead vertices such that two working batteries (uncolored vertices) never get tested together, that is, there is no edge between them. In graph theory lingo, we want to find a vertex cover of size 4 or smaller; this is defined as a set of vertices such that each edge of the graph is incident to at least one vertex of the set. (We incidentally ignore unconnected vertices in all this, since they don't get tested.)

If the graph G G has a vertex of degree 3 or higher, color it red. The 3 (or more) edges from that vertex have been accounted for; take the remaining edges not incident to the already-red vertex and color one vertex of each, and we have our vertex cover. (Sample below.)

Otherwise, there will be two vertices of degree 2 that are not incident. (This is always true given 8 vertices and 6 edges -- if you don't see why, think pigeonhole principle .) Color each of those vertices, and then there will be 2 edges unaccounted for. Color one vertex of each of those edges, and we have our vertex cover. (Sample below.)

What about this.....

Put the first 6 batteries into 2 lots of 3

If G=Good and B=Bad then the layout of group one will be one of the following:-

a) 3G/0B b) 2G/1B c) 1G/2B d) 0G/3B

In (a) 2 good batteries will be found on try 1; in (b) no more than 3 attempts

In (d) 3B means we have had 3 tries, all failed. However, we now know that at most there is only 1B in group 2. We shall find a good pair in a maximum of 3 tries in this group. Consequently a maximum of 6 tries overall.

In scenario (c), there will be 1, 2 or 3 good batteries in group 2 - if 1 then all 3 tries fail then batteries 7 & 8 must be good (without the need to test) If 2 good batteries then a minimum of 3 tests to find a good pair (6 overall). If 3 good batteries, a pair will be found at the first test.

Never more than 6 tries!!

Geoff Holmes - 3 years, 11 months ago

Log in to reply

In scenario c, you've tried 3+3=6, and need to put the two left out batteries in for a 7th try to get a good pair, so it's still 7.

John Hollander - 3 years, 11 months ago

John Hollander, No, four "bad" batteries have been detected, ergo the other 4 MUST be good - I don't need to test if we have ruled out the duff 4.... the clue is in the question!!

Geoff Holmes - 3 years, 11 months ago

Can anyone please clarify this graph theory sub-solution? In the first sample, let's label the circles as: ABCD EFGH It seems like you could draw a seventh line between, say, C and H, where you would still have a dead combination. Which would mean that the graph theory illustration doesn't actually prove anything about the minimum number of tests required being 7. Can anyone tell me what I'm missing here?

Y C - 2 years, 11 months ago
Astro Enthusiast
Jun 25, 2017

My solution is simple.

There are 2 pairs of good batteries and 2 pairs of bad batteries.

So for the flashlight to turn on, you must use 2 good batteries of four. For the flashlight NOT to turn on, you must use 2 bad batteries altogether. Not only that, but to combine one good battery with one bad battery.

So the combination of one good battery and one bad battery is at least four, assuming that you used all the batteries only once: 4 (1 good battery + 1 bad battery) = FAILED 2 (1 bad battery + 1 bad battery) = FAILED 1 (1 good battery + 1 good battery) = SUCCEED!

Your solution doesn't make any sense. After your first 4 tries you didn't take into account that you still don't know which battery is good and which is not. So after producing the worst case scenario of the first 4 tries, you have no way of selecting pairs that are only bad. When you try to re-pair them, you can just as well end up with different pairs of good and bad batteries - and not just two of them, but 8 in total (although after 5 you can already find 2 good ones).

József Inczefi - 3 years, 11 months ago

I don't understand it 😅

Abanoub Victor - 3 years, 11 months ago

Log in to reply

Let's try it through an example: suppose we label the 8 batteries from 1 to 8. Then take 1 and 2, 3 and 4, etc. Neither of these works. This means, that all of them have 1 good and one bad battery, otherwise one of the pairs would have had 2 good ones and that would've worked. So now the problem is, that if we cross-pair them, we can't directly eliminate bad batteries, since if we pick one from the first pair, that can be either good or bad, then the same for all groups. So a second round of pairing could also result in 4 not working pairs. Also, if we only take the first two groups, in which we now know that there are 2 good and 2 bad batteries, we also need at most 4 tries to find the 2 good ones. So with this starting strategy, 8 tries or more yields only results.

József Inczefi - 3 years, 11 months ago

Log in to reply

You are wrong...

Madhab Sikder - 3 years, 11 months ago

Log in to reply

@Madhab Sikder No, you are wrong. I've demonstrated why I am right. If you can't do the same, please refrain from commenting.

József Inczefi - 3 years, 11 months ago

I also used the same technique. It is the simplest way..

Madhab Sikder - 3 years, 11 months ago
John Hollander
Jun 30, 2017

Split the batteries into two groups: (A, B, C, D) and (E, F, G, H). Try the following AB, AC, AD, BC, BD, CD (these are all the possible combinations of the first group). If one of these succeeds, you've found a pair, if neither does, any combination of E, F, G, H will succeed (since all four of the first set are dead, all of the remaining ones are good). Thus you have 7 tries max.

This is not complete. While you have shown that 7 is achievable, you have not proven that 7 is the lowest bound. In other words, 7 is possible, but why can't the answer be less than 7?

Pi Han Goh - 3 years, 11 months ago

Actually, this does not show that 7 is achievable.

If none of AB, AC, AD, BC, BD, CD light the torch it is still possible that there is one good battery in (A, B, C, D). Thus it is possible that there will still be one dead battery in (E, F, G, H) which will take two further tests (EF & GH) to eliminate = 8 tries.

For the record: I also got it in 8 tries via a different set of combinations (AB CD EF GH all fail => each pair has one good + one bad battery so AC AD BC BD must produce a good pair) but I see the more cunning solution by Andy Hayes achieves it in 7.

Chris Kowalski - 3 years, 9 months ago
Jimbo Juice
Jun 29, 2017

Form 4 groups of 2 batteries: G1, G2, G3, G4. Worst case scenario, all four groups fail => at least one dead battery from each group => there doesn't exist a group with fail-fail (and success-success, obviously) since fail-fail implies there exists at least one group of success-success by counting. Hence, WLOG, choose G1 and G2. Choose any A1 from G1 and test with both elements G2. Worst case, both fail if A1 is dead. Test B1 from G1 with A2, B2 from G2. Worst case, first trial fails because A2 is dead. Hence, B1 and B2 must work. Total trials = 7.

Yeah, but you will only get the flashlight working on the 8th time. The fact that you know after the end of the 7th trial that the 8th will work doesn't allow you to not count it. Your method is nice, but it requires 8 moves and is thus not the optimal that the question is asking for, as that is 7.

Harry D - 3 years, 11 months ago

The operative word is, "guarantee" for it to be a certainty that the next try will work there must be no more bad batteries left and the worst case must be considered. Worst case would be using max tries, each try would be one good and one bad battery, using up all the bad batteries as slowly as possible (in four tries). Only then could the fifth try be guaranteed succeed.

Camille Lee - 3 years, 11 months ago
Mathew Rizkalla
Jun 30, 2017

Minimum number of attempts assumes selecting all the bad batteries first

4C2 (selecting 2 batteries from the 4 dead ones) = 6 combinations.

Next one is sure to be 2 good ones so +1 more attempt

7 Combinations

Is this the best algorithm? Can we do better than 7? Why not?

Pi Han Goh - 3 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...