Welcome to techInterview, a site for technical interview questions, brain teasers, puzzles, quizzles (whatever the heck those are) and other things that make you think!
It’s the middle ages, you’re travelling across europe and you want to find the way to vienna. you come to a crossroads, now there are two ways to go. at the crossroads stand a knight and a knave. the knight answers every question truthfully. the knave answers every question falsely. you don’t know which guy is which. how can you figure out which road leads to Vienna by only asking one question?
Many people try “what would the other man say if I asked him which way to Vienna?” But for that to work, the knight would have to know that the other man is a knave, and the knave would have to know that the other man is a knight; it’s not clear that either of these is a given.
To cope with that, you can ask “assuming the other man has the opposite predilection regarding truth-telling from what you do, what would he say if I asked him which way to Vienna?”
More interestingly, you can ask “if you were to ask yourself which way to Vienna, what would you say?” But before risking that question, I’d want a few more details about how the knave is wired up. What does it mean, to lie to oneself? Is such a thing even possible, regardless of what psychoanalysts might claim?
Furthermore, travelling through Europe in the middle ages, it’s a bit of a rash assumption that people you meet at a crossroad would understand English. If you only have 1 question, you have to frame a question that is meaningful in all locally spoken languages (like writing a program that is both legal Fortran and legal C). Your question doesn’t have to mean exactly the same thing in each language, as long as each possible answer carries in itself an indication of which language it is in.
Or you could try the universal language of mime. Say “Vienna” and open your arms wide with a questioning look. But how would you mime “if you were to ask the other man …” (or “if you were to ask yourself …”) ?