by Guest » Wed Jan 11, 2017 8:15 pm
The trick is to consider what happens when you have two pears with different weights. There are only two possibilities:
(A) both are rotten
or
(B) one is good and the other is rotten
In both cases if we ignored both those pears (pretended like they didn't exist) the number of good pears is still more than the number of bad pears.
For example if we knew (by magic) that there were in total 4 good pears and 3 bad pears, and we encounter two pears of different weights, then after we ignore them we would know there are 4 good pears and 1 bad if we are in case (A) or that there are 3 good and 2 bad if we are in case (B). In either case there was still more good pears than bad.
So the solution is to do the following:
1) Pick up a pear and put it into your lunch box.
Keep track of how many pears you've encountered (so far it is 1).
Go to step 2.
2) Try to move to the next pear.
If there are no more pears: Every pear you've encountered is the same weight as the one in your lunch box, so it must be a good pear, and you are done.
If there is another pear: Go to step 3.
3) Weigh the pear you just found with the pear in your lunch box.
Remember to keep track of how many pears you've encountered by adding one to the number encountered so far.
If the pears weigh the same: (Notice that all the pears you've encountered weigh the same as the one in your lunch box.) Go to step 2.
If the pears have different weights: (Notice that all the pears you've encountered weigh the same as the one in your lunch box except for this last one.) Go to step 4.
4) If we've only encountered 2 pears: Ignore them (pretend they don't exist), throw away the pear in your lunch box, reset the number of pears encountered to 0, and go to step 1.
If we've encountered more than 2 pears: All the pears you've encountered weigh the same except for the very last pear you found, so ignore the last pear and the second last pear (they must have different weights). Subtract two from the number of pears encountered (to account for the pears we are now pretending don't exist), and go to step 2. (Notice that after we ignored the two pears we are back in the situation that all pears we've found have the same weight).
As an example suppose the pears weigh 1, 1, 1, 5, 4, 3, 2, 2, 4, 2, 2, 2, 2, 2, 2:
1 ) Find pear (it weighs 1), you put it in your lunch box. In total you've found 1 pear [weights: 1].
2 ) Find pear (it weighs 1). It weighs the same as the pear in your lunch box. In total you've found 2 pears [weights: 1, 1].
3 ) Find pear (it weighs 1). It weighs the same as the pear in your lunch box. In total you've found 3 pears [weights: 1, 1, 1].
4 ) Find pear (it weighs 5). It has a different weight to the pear in your lunch box. You pretend the last two pears don't exist. In total you've found 2 pears [weights: 1, 1].
5 ) Find pear (it weighs 4). It has a different weight to the pear in your lunch box. You pretend the last two pears don't exist. In total you've found 1 pear [weights: 1].
6 ) Find pear (it weighs 3). It has a different weight to the pear in your lunch box. You pretend the last two pears don't exist. In total you've found 0 pears.
7 ) Find pear (it weighs 2), you put it in your lunch box. In total you've found 1 pear [weights: 2].
8 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 2 pears [weights: 2, 2].
9 ) Find pear (it weighs 4). It has a different weight to the pear in your lunch box. You pretend the last two pears don't exist. In total you've found 1 pear [weights: 2].
10 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 2 pears [weights: 2, 2].
11 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 3 pears [weights: 2, 2, 2].
12 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 4 pears [weights: 2, 2, 2, 2].
13 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 5 pears [weights: 2, 2, 2, 2, 2].
14 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 6 pears [weights: 2, 2, 2, 2, 2, 2].
15 ) Find pear (it weighs 2). It weighs the same as the pear in your lunch box. In total you've found 7 pears [weights: 2, 2, 2, 2, 2, 2, 2].
16 ) No more pears found. In total there are 7 pears all weighing the same as the pear in your lunch box, so it must be a good pear.
In reality there were 8 good pears and 7 rotten pears, but because we pretended some pears didn't exist, we end up pretending that there were only 7 pears all of which were good.
Hope this helped,
R. Baber.