War has broken out in the kingdom. The king's castle is guarded pretty heavily, by guards with instructions to kill anyone who can't produce the correct password.
Unbeknownst to the guards, the beggar near the main gate is in fact an enemy spy. He listens intently as the first knight approaches. "Six!", the guard calls out. "Three," answers the knight. He is allowed through. "Aha," the spy thinks to himself.
But he needs to be sure. He sees another knight approaching and listens in on his exchange with the guard. "Twelve!" "Six!"
The spy leaves, and returns dressed as a knight. "Eighteen!" The spy answers "nine" and is killed on the spot by the guards.