I love the story behind this math teacher's challenge. I heard a different version of this where it was a guard doing rounds and toggling the state of cell doors. The question at the end was how many convicts could just walk out after the guard had finished his rounds. I actually turned this into an exercise for first year students of the course "computertechnologie" back in my predoc years at Ghent. The catch was that they had to code up the algorithm in Motorola MC68000 assembler (most did a great job too). Yup, fun times.