29 hostages are captured by a terrorist. They are told, "You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another."
"There is an isolated switch room here, which contains two light switches labelled A and B, each of which can be in either the 'on' or the 'off' position. I am not telling you their present positions. The switches are not connected to anything."
"After today from time to time whenever I feel so inclined, I will select one hostage at random and escort him to the switch room. This hostage will select one of the two switches and reverse its position. He must move one, and only one of the switches. He can't move both and he can't move none either. Then he'll be led back to his cell."
“I will then take the next hostage there, and he'll be instructed to do the same thing. I am going to choose hostages at random. I may choose the same guy three times in a row, or I may jump around and come back."
"But, given enough time, everyone will eventually visit the switch room as many times as everyone else. "No one else will enter the switch room until I lead them."
"At any time anyone of you may declare to me, 'We have all visited the switch room.' and be 100% sure. "If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will be fed to the alligators."
What is the strategy they come up with so that they can be free?