[ad_1]
The following ought to display that six checks (7 “tries”) is perfect.
To present n out of n+1 batteries are lifeless,
all pairings of the n+1 batteries should be examined. For n >= 1, we’ve got n(n+1)/2 pairings.
Thus:
1 check is required to point out that 1 of two batteries is lifeless
3 checks are required to point out that 2 of three batteries are lifeless
6 checks are required to point out that 3 of 4 batteries are lifeless
And at 6 checks, this matches hexomino’s answer with out guaranteeing a working pair, so we are able to ignore this and the opportunity of marking 4 in 5 as lifeless for the needs of optimization.
Recall we’re optimizing for the worst luck, so we think about that we can’t discover a working set of batteries till we definitively establish/remove the lifeless ones. This additionally implies that eliminating batteries we do not know are lifeless is identical as eliminating reside batteries.
This makes our purpose:
1. eliminating 4 batteries as lifeless
whereas
2. protecting 2 different batteries not eradicated (which then should be reside)
Some notes on brute-forcing:
For any group of n >= 3 batteries containing a minimum of 1 lifeless battery and ok >= 2 reside batteries, the worst case requires we execute
n(n-1)/2 – ok(k-1)/2 failed checks in an effort to establish the entire lifeless batteries (and therefore the reside ones).
As a corrollary, we won’t establish particular person reside/lifeless batteries in a bunch if
we do not know that a minimum of two are reside, so brute-forcing a bunch is not an choice with out a minimum of two reside batteries.
So, for instance, take a bunch of two reside batteries and a couple of lifeless batteries.
If these are the one batteries we have not eradicated, we should brute-force the group in an effort to establish each reside ones, which takes 5 checks (suboptimal per hexomino’s answer; 1 check alone cannot establish a bunch of two reside and a couple of lifeless batteries), making the 2-live, 2-dead subproblem a part of solely non-optimal options.
We arrive at this subproblem by
working two checks to remove one lifeless and one reside battery every,
so the optimum answer eliminates
one or fewer units of 1 reside, 1 lifeless.
Only 2 different eventualities stay:
If we remove one such set, we’re left with 3 reside, 3 lifeless after 1 check; brute-forcing from right here is suboptimal, so we use 3 checks to remove 2 lifeless, 1 reside to reach at 1 lifeless, 2 reside, which should be brute-forced and requires 2 extra checks.
(complete 6 checks)
If we do not remove any 1-live, 1-dead units, our solely choice is utilizing 3 checks twice, every time eliminating 2 lifeless, 1 reside, to reach at 2 reside, which requires no additional checks.
(that is hexomino’s answer, which additionally requires 6 checks)
[ad_2]