Each time when two balls are picked out of the pocket: 1) If both of them are white, a white is put back, so white -1, black unchanged. 2) If both of them are black, a white is put back, so white +1, black -2. 3) If one is white and one is black, a black is put back, so white -1, black unchanged.
So no matter what color the balls are, the total number of balls is decreased by 1, and the number of black balls is either decreased by 2, or remain unchanged. The *parity* of the black balls always stays the same, i.e. when it's odd, it's always odd, when it's even, it's always even. So what happens when there's only one ball left in the pocket? You got it! If the original number of black balls is odd, then the last ball must be black (still odd). If the original number of black balls is even, then the last ball must not be black (still even), and it has to be white! On Sep 19, 2:44 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi All of you > I would like to know the algorithm used to solve the problem of the > 'old magician'(Question no1) that was in the practice test held on > saturday.I hope you may help me with this. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-code?hl=en -~----------~----~----~----~------~----~------~--~---
