But WHY did the other prisoner set the light off? Basically, what you said is: the last prisoner set the light off if he has been into the room before, but this can lead to an error. Let's asume only ONE prisoner is called for 5 straight days, and he sets the light off when he is called again the last day. So another prisoner gets called, it is the 6th day and the light is off, so he claims to be the last one, and is wrong.
I say it's mathematically impossible, DanielB says it can be done. Anyone else here might want to give an opinion, so we can decide once and for all if this one has a solution?