Island of Knights, Knaves and Spies












7












$begingroup$


There is an island with $N$ inhabitants (for example $A_1, A_2, dots, A_N$), each of them is either a knight, a knave, or a spy. As usual:





  • knights will always tell the truth upon answering a question,


  • knaves will always lie,

  • and spies can do both (however they always alternate the truth value of their answers, i.e. if they lied they definitely will tell the truth upon the next answer, and vice versa).


You must determine the correct identities of all $A_i$'s by asking questions, which have to be of one of the following forms:




  • Is $A_j$ a knight/knave/spy? (It includes the $i=j$ case, so you particularly can ask "Are you a knight/knave/spy?") The answer will be either "yes" or "no".

  • How many knights/knaves/spies are among you? The answer will be an integer between $0$ and $N$, inclusively (so, for example for $N=20$, even a knave wouldn't answer $25$, $-3$, or $8.5$).


It's very easy to construct a solution with $2N$ questions, namely asking each islander twice: "Are you a spy?", because




  • a knight will say "no" at both times (since knights never lie, and a knight is indeed not a spy),

  • a knave will say "yes" both times (vice versa, a knave always lies, and still isn't a spy),

  • and a spy will give different answers each time (because spies never lie or tell the truth twice in a row).


So, after 2 questions we can reveal the identity of one given islander.



The question to this puzzle is: Can the number of questions be less than $2N$, and if it can, what's the minimum number of questions needed? (In the solution above, the second type of questions was not even used.)










share|improve this question











$endgroup$












  • $begingroup$
    I take it we should assume that all the islanders know what everyone is?
    $endgroup$
    – Gareth McCaughan
    5 hours ago










  • $begingroup$
    I assume you are looking for a strategy that guarantees that you will know the identity of every islander with fewer than 2N questions even in the worst case. Correct?
    $endgroup$
    – Hugh Meyers
    3 hours ago












  • $begingroup$
    ... and if so, then I suppose the worst case has to be that everyone is a knave thus making the second question valueless.
    $endgroup$
    – Hugh Meyers
    3 hours ago






  • 1




    $begingroup$
    Can I subdivide groups? For example, If I split off a group of M < N and ask the second question, will they respond (0..M) or (0..N)?
    $endgroup$
    – Chris Cudmore
    2 hours ago
















7












$begingroup$


There is an island with $N$ inhabitants (for example $A_1, A_2, dots, A_N$), each of them is either a knight, a knave, or a spy. As usual:





  • knights will always tell the truth upon answering a question,


  • knaves will always lie,

  • and spies can do both (however they always alternate the truth value of their answers, i.e. if they lied they definitely will tell the truth upon the next answer, and vice versa).


You must determine the correct identities of all $A_i$'s by asking questions, which have to be of one of the following forms:




  • Is $A_j$ a knight/knave/spy? (It includes the $i=j$ case, so you particularly can ask "Are you a knight/knave/spy?") The answer will be either "yes" or "no".

  • How many knights/knaves/spies are among you? The answer will be an integer between $0$ and $N$, inclusively (so, for example for $N=20$, even a knave wouldn't answer $25$, $-3$, or $8.5$).


It's very easy to construct a solution with $2N$ questions, namely asking each islander twice: "Are you a spy?", because




  • a knight will say "no" at both times (since knights never lie, and a knight is indeed not a spy),

  • a knave will say "yes" both times (vice versa, a knave always lies, and still isn't a spy),

  • and a spy will give different answers each time (because spies never lie or tell the truth twice in a row).


So, after 2 questions we can reveal the identity of one given islander.



The question to this puzzle is: Can the number of questions be less than $2N$, and if it can, what's the minimum number of questions needed? (In the solution above, the second type of questions was not even used.)










share|improve this question











$endgroup$












  • $begingroup$
    I take it we should assume that all the islanders know what everyone is?
    $endgroup$
    – Gareth McCaughan
    5 hours ago










  • $begingroup$
    I assume you are looking for a strategy that guarantees that you will know the identity of every islander with fewer than 2N questions even in the worst case. Correct?
    $endgroup$
    – Hugh Meyers
    3 hours ago












  • $begingroup$
    ... and if so, then I suppose the worst case has to be that everyone is a knave thus making the second question valueless.
    $endgroup$
    – Hugh Meyers
    3 hours ago






  • 1




    $begingroup$
    Can I subdivide groups? For example, If I split off a group of M < N and ask the second question, will they respond (0..M) or (0..N)?
    $endgroup$
    – Chris Cudmore
    2 hours ago














7












7








7





$begingroup$


There is an island with $N$ inhabitants (for example $A_1, A_2, dots, A_N$), each of them is either a knight, a knave, or a spy. As usual:





  • knights will always tell the truth upon answering a question,


  • knaves will always lie,

  • and spies can do both (however they always alternate the truth value of their answers, i.e. if they lied they definitely will tell the truth upon the next answer, and vice versa).


You must determine the correct identities of all $A_i$'s by asking questions, which have to be of one of the following forms:




  • Is $A_j$ a knight/knave/spy? (It includes the $i=j$ case, so you particularly can ask "Are you a knight/knave/spy?") The answer will be either "yes" or "no".

  • How many knights/knaves/spies are among you? The answer will be an integer between $0$ and $N$, inclusively (so, for example for $N=20$, even a knave wouldn't answer $25$, $-3$, or $8.5$).


It's very easy to construct a solution with $2N$ questions, namely asking each islander twice: "Are you a spy?", because




  • a knight will say "no" at both times (since knights never lie, and a knight is indeed not a spy),

  • a knave will say "yes" both times (vice versa, a knave always lies, and still isn't a spy),

  • and a spy will give different answers each time (because spies never lie or tell the truth twice in a row).


So, after 2 questions we can reveal the identity of one given islander.



The question to this puzzle is: Can the number of questions be less than $2N$, and if it can, what's the minimum number of questions needed? (In the solution above, the second type of questions was not even used.)










share|improve this question











$endgroup$




There is an island with $N$ inhabitants (for example $A_1, A_2, dots, A_N$), each of them is either a knight, a knave, or a spy. As usual:





  • knights will always tell the truth upon answering a question,


  • knaves will always lie,

  • and spies can do both (however they always alternate the truth value of their answers, i.e. if they lied they definitely will tell the truth upon the next answer, and vice versa).


You must determine the correct identities of all $A_i$'s by asking questions, which have to be of one of the following forms:




  • Is $A_j$ a knight/knave/spy? (It includes the $i=j$ case, so you particularly can ask "Are you a knight/knave/spy?") The answer will be either "yes" or "no".

  • How many knights/knaves/spies are among you? The answer will be an integer between $0$ and $N$, inclusively (so, for example for $N=20$, even a knave wouldn't answer $25$, $-3$, or $8.5$).


It's very easy to construct a solution with $2N$ questions, namely asking each islander twice: "Are you a spy?", because




  • a knight will say "no" at both times (since knights never lie, and a knight is indeed not a spy),

  • a knave will say "yes" both times (vice versa, a knave always lies, and still isn't a spy),

  • and a spy will give different answers each time (because spies never lie or tell the truth twice in a row).


So, after 2 questions we can reveal the identity of one given islander.



The question to this puzzle is: Can the number of questions be less than $2N$, and if it can, what's the minimum number of questions needed? (In the solution above, the second type of questions was not even used.)







combinatorics optimization liars






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









Gareth McCaughan

68.3k3173267




68.3k3173267










asked 6 hours ago









trolley813trolley813

1,41648




1,41648












  • $begingroup$
    I take it we should assume that all the islanders know what everyone is?
    $endgroup$
    – Gareth McCaughan
    5 hours ago










  • $begingroup$
    I assume you are looking for a strategy that guarantees that you will know the identity of every islander with fewer than 2N questions even in the worst case. Correct?
    $endgroup$
    – Hugh Meyers
    3 hours ago












  • $begingroup$
    ... and if so, then I suppose the worst case has to be that everyone is a knave thus making the second question valueless.
    $endgroup$
    – Hugh Meyers
    3 hours ago






  • 1




    $begingroup$
    Can I subdivide groups? For example, If I split off a group of M < N and ask the second question, will they respond (0..M) or (0..N)?
    $endgroup$
    – Chris Cudmore
    2 hours ago


















  • $begingroup$
    I take it we should assume that all the islanders know what everyone is?
    $endgroup$
    – Gareth McCaughan
    5 hours ago










  • $begingroup$
    I assume you are looking for a strategy that guarantees that you will know the identity of every islander with fewer than 2N questions even in the worst case. Correct?
    $endgroup$
    – Hugh Meyers
    3 hours ago












  • $begingroup$
    ... and if so, then I suppose the worst case has to be that everyone is a knave thus making the second question valueless.
    $endgroup$
    – Hugh Meyers
    3 hours ago






  • 1




    $begingroup$
    Can I subdivide groups? For example, If I split off a group of M < N and ask the second question, will they respond (0..M) or (0..N)?
    $endgroup$
    – Chris Cudmore
    2 hours ago
















$begingroup$
I take it we should assume that all the islanders know what everyone is?
$endgroup$
– Gareth McCaughan
5 hours ago




$begingroup$
I take it we should assume that all the islanders know what everyone is?
$endgroup$
– Gareth McCaughan
5 hours ago












$begingroup$
I assume you are looking for a strategy that guarantees that you will know the identity of every islander with fewer than 2N questions even in the worst case. Correct?
$endgroup$
– Hugh Meyers
3 hours ago






$begingroup$
I assume you are looking for a strategy that guarantees that you will know the identity of every islander with fewer than 2N questions even in the worst case. Correct?
$endgroup$
– Hugh Meyers
3 hours ago














$begingroup$
... and if so, then I suppose the worst case has to be that everyone is a knave thus making the second question valueless.
$endgroup$
– Hugh Meyers
3 hours ago




$begingroup$
... and if so, then I suppose the worst case has to be that everyone is a knave thus making the second question valueless.
$endgroup$
– Hugh Meyers
3 hours ago




1




1




$begingroup$
Can I subdivide groups? For example, If I split off a group of M < N and ask the second question, will they respond (0..M) or (0..N)?
$endgroup$
– Chris Cudmore
2 hours ago




$begingroup$
Can I subdivide groups? For example, If I split off a group of M < N and ask the second question, will they respond (0..M) or (0..N)?
$endgroup$
– Chris Cudmore
2 hours ago










2 Answers
2






active

oldest

votes


















4












$begingroup$

It takes




at most about $5N/3$ questions.




Suppose




we know a knight or spy and want to find the identities of $k$ islanders. We can find the division of $k$ into knights, knaves, or spies by asking the knight/spy at most five questions of the second type. Suppose the most represented type is X. Then we ask the knight/spy whether each of the $k$ is X. This determines exactly which of them is X, so we can determine the remainder by asking the knight/spy whether each of them is one of the remaining types. In the worst case, each of the classes is equally represented among the $k$, so that this takes about $5k/3$ questions.




Now




our strategy is to find a knight/spy. First we use the known two question strategy to determine the identity of an islander. If they are a knave, we keep asking them whether other islanders are knaves. Each knave discovered in this way requires only one question, so in the worst case we quickly discover a knight/spy, and we use about $5N/3$ questions in total.







share|improve this answer











$endgroup$





















    1












    $begingroup$

    Wrong answer



    [EDITED to add:] Oops, the following is all wrong; thanks to @hexomino for pointing out in comments that I misinterpreted the question. I'm leaving this here rather than deleting it because (1) it's possible that some idea in it is salvageable and (2) I don't believe in making myself look better by deleting my mistakes :-). (I might delete it later to reduce clutter.)



    The minimal number of questions




    is less than $2N$, at least when $N$ is not too small. In fact, it's never more than $frac43N$ plus a few.




    Here's why.




    First, use two "are you a spy?" questions to establish what #1 is, and also (if they're a spy) which way around their truth-telling and lying answers are. We now have three cases. If #1 is a knight then we can just ask them about everyone else, and we're done in $N+1$ questions. If #1 is a spy then we ask them about everyone else -- once, asking "what is X?", when they are telling the truth, and twice, asking binary questions, when they are lying. Every 4 questions we find out about 3 people, so we take approximately $frac43N$ questions.







    The hardest case is when #1 is a knave. Here's one way to proceed. Ask them "is X a knave?" about each other person in turn. If they say "no" then we have correctly identified that X is a knave, and if that's all that ever happens then again we're done in $N+1$ questions. If at some point they say "yes" then we have found a non-knave. We can then ask that person two questions to figure out exactly what they are and (if they're a spy) what their "phase" is, and then proceed as above, asking them about everyone else in turn.







    In the worst case: we take two questions to establish that #1 is a knave; we take one more question to establish that #2 is knot a knave; we take two questions to establish that #2 is a spy and phind his phase; we then have $N-2$ people to figure out, divide them into $leftlceilfrac{N-2}3rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfrac{N-2}3rightrceil+5$ questions. I make no claim that this is optimal, though.







    share|improve this answer











    $endgroup$









    • 1




      $begingroup$
      I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
      $endgroup$
      – hexomino
      2 hours ago










    • $begingroup$
      oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
      $endgroup$
      – Gareth McCaughan
      2 hours ago












    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "559"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f83179%2fisland-of-knights-knaves-and-spies%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4












    $begingroup$

    It takes




    at most about $5N/3$ questions.




    Suppose




    we know a knight or spy and want to find the identities of $k$ islanders. We can find the division of $k$ into knights, knaves, or spies by asking the knight/spy at most five questions of the second type. Suppose the most represented type is X. Then we ask the knight/spy whether each of the $k$ is X. This determines exactly which of them is X, so we can determine the remainder by asking the knight/spy whether each of them is one of the remaining types. In the worst case, each of the classes is equally represented among the $k$, so that this takes about $5k/3$ questions.




    Now




    our strategy is to find a knight/spy. First we use the known two question strategy to determine the identity of an islander. If they are a knave, we keep asking them whether other islanders are knaves. Each knave discovered in this way requires only one question, so in the worst case we quickly discover a knight/spy, and we use about $5N/3$ questions in total.







    share|improve this answer











    $endgroup$


















      4












      $begingroup$

      It takes




      at most about $5N/3$ questions.




      Suppose




      we know a knight or spy and want to find the identities of $k$ islanders. We can find the division of $k$ into knights, knaves, or spies by asking the knight/spy at most five questions of the second type. Suppose the most represented type is X. Then we ask the knight/spy whether each of the $k$ is X. This determines exactly which of them is X, so we can determine the remainder by asking the knight/spy whether each of them is one of the remaining types. In the worst case, each of the classes is equally represented among the $k$, so that this takes about $5k/3$ questions.




      Now




      our strategy is to find a knight/spy. First we use the known two question strategy to determine the identity of an islander. If they are a knave, we keep asking them whether other islanders are knaves. Each knave discovered in this way requires only one question, so in the worst case we quickly discover a knight/spy, and we use about $5N/3$ questions in total.







      share|improve this answer











      $endgroup$
















        4












        4








        4





        $begingroup$

        It takes




        at most about $5N/3$ questions.




        Suppose




        we know a knight or spy and want to find the identities of $k$ islanders. We can find the division of $k$ into knights, knaves, or spies by asking the knight/spy at most five questions of the second type. Suppose the most represented type is X. Then we ask the knight/spy whether each of the $k$ is X. This determines exactly which of them is X, so we can determine the remainder by asking the knight/spy whether each of them is one of the remaining types. In the worst case, each of the classes is equally represented among the $k$, so that this takes about $5k/3$ questions.




        Now




        our strategy is to find a knight/spy. First we use the known two question strategy to determine the identity of an islander. If they are a knave, we keep asking them whether other islanders are knaves. Each knave discovered in this way requires only one question, so in the worst case we quickly discover a knight/spy, and we use about $5N/3$ questions in total.







        share|improve this answer











        $endgroup$



        It takes




        at most about $5N/3$ questions.




        Suppose




        we know a knight or spy and want to find the identities of $k$ islanders. We can find the division of $k$ into knights, knaves, or spies by asking the knight/spy at most five questions of the second type. Suppose the most represented type is X. Then we ask the knight/spy whether each of the $k$ is X. This determines exactly which of them is X, so we can determine the remainder by asking the knight/spy whether each of them is one of the remaining types. In the worst case, each of the classes is equally represented among the $k$, so that this takes about $5k/3$ questions.




        Now




        our strategy is to find a knight/spy. First we use the known two question strategy to determine the identity of an islander. If they are a knave, we keep asking them whether other islanders are knaves. Each knave discovered in this way requires only one question, so in the worst case we quickly discover a knight/spy, and we use about $5N/3$ questions in total.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 hours ago

























        answered 2 hours ago









        noednenoedne

        9,65312667




        9,65312667























            1












            $begingroup$

            Wrong answer



            [EDITED to add:] Oops, the following is all wrong; thanks to @hexomino for pointing out in comments that I misinterpreted the question. I'm leaving this here rather than deleting it because (1) it's possible that some idea in it is salvageable and (2) I don't believe in making myself look better by deleting my mistakes :-). (I might delete it later to reduce clutter.)



            The minimal number of questions




            is less than $2N$, at least when $N$ is not too small. In fact, it's never more than $frac43N$ plus a few.




            Here's why.




            First, use two "are you a spy?" questions to establish what #1 is, and also (if they're a spy) which way around their truth-telling and lying answers are. We now have three cases. If #1 is a knight then we can just ask them about everyone else, and we're done in $N+1$ questions. If #1 is a spy then we ask them about everyone else -- once, asking "what is X?", when they are telling the truth, and twice, asking binary questions, when they are lying. Every 4 questions we find out about 3 people, so we take approximately $frac43N$ questions.







            The hardest case is when #1 is a knave. Here's one way to proceed. Ask them "is X a knave?" about each other person in turn. If they say "no" then we have correctly identified that X is a knave, and if that's all that ever happens then again we're done in $N+1$ questions. If at some point they say "yes" then we have found a non-knave. We can then ask that person two questions to figure out exactly what they are and (if they're a spy) what their "phase" is, and then proceed as above, asking them about everyone else in turn.







            In the worst case: we take two questions to establish that #1 is a knave; we take one more question to establish that #2 is knot a knave; we take two questions to establish that #2 is a spy and phind his phase; we then have $N-2$ people to figure out, divide them into $leftlceilfrac{N-2}3rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfrac{N-2}3rightrceil+5$ questions. I make no claim that this is optimal, though.







            share|improve this answer











            $endgroup$









            • 1




              $begingroup$
              I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
              $endgroup$
              – hexomino
              2 hours ago










            • $begingroup$
              oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
              $endgroup$
              – Gareth McCaughan
              2 hours ago
















            1












            $begingroup$

            Wrong answer



            [EDITED to add:] Oops, the following is all wrong; thanks to @hexomino for pointing out in comments that I misinterpreted the question. I'm leaving this here rather than deleting it because (1) it's possible that some idea in it is salvageable and (2) I don't believe in making myself look better by deleting my mistakes :-). (I might delete it later to reduce clutter.)



            The minimal number of questions




            is less than $2N$, at least when $N$ is not too small. In fact, it's never more than $frac43N$ plus a few.




            Here's why.




            First, use two "are you a spy?" questions to establish what #1 is, and also (if they're a spy) which way around their truth-telling and lying answers are. We now have three cases. If #1 is a knight then we can just ask them about everyone else, and we're done in $N+1$ questions. If #1 is a spy then we ask them about everyone else -- once, asking "what is X?", when they are telling the truth, and twice, asking binary questions, when they are lying. Every 4 questions we find out about 3 people, so we take approximately $frac43N$ questions.







            The hardest case is when #1 is a knave. Here's one way to proceed. Ask them "is X a knave?" about each other person in turn. If they say "no" then we have correctly identified that X is a knave, and if that's all that ever happens then again we're done in $N+1$ questions. If at some point they say "yes" then we have found a non-knave. We can then ask that person two questions to figure out exactly what they are and (if they're a spy) what their "phase" is, and then proceed as above, asking them about everyone else in turn.







            In the worst case: we take two questions to establish that #1 is a knave; we take one more question to establish that #2 is knot a knave; we take two questions to establish that #2 is a spy and phind his phase; we then have $N-2$ people to figure out, divide them into $leftlceilfrac{N-2}3rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfrac{N-2}3rightrceil+5$ questions. I make no claim that this is optimal, though.







            share|improve this answer











            $endgroup$









            • 1




              $begingroup$
              I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
              $endgroup$
              – hexomino
              2 hours ago










            • $begingroup$
              oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
              $endgroup$
              – Gareth McCaughan
              2 hours ago














            1












            1








            1





            $begingroup$

            Wrong answer



            [EDITED to add:] Oops, the following is all wrong; thanks to @hexomino for pointing out in comments that I misinterpreted the question. I'm leaving this here rather than deleting it because (1) it's possible that some idea in it is salvageable and (2) I don't believe in making myself look better by deleting my mistakes :-). (I might delete it later to reduce clutter.)



            The minimal number of questions




            is less than $2N$, at least when $N$ is not too small. In fact, it's never more than $frac43N$ plus a few.




            Here's why.




            First, use two "are you a spy?" questions to establish what #1 is, and also (if they're a spy) which way around their truth-telling and lying answers are. We now have three cases. If #1 is a knight then we can just ask them about everyone else, and we're done in $N+1$ questions. If #1 is a spy then we ask them about everyone else -- once, asking "what is X?", when they are telling the truth, and twice, asking binary questions, when they are lying. Every 4 questions we find out about 3 people, so we take approximately $frac43N$ questions.







            The hardest case is when #1 is a knave. Here's one way to proceed. Ask them "is X a knave?" about each other person in turn. If they say "no" then we have correctly identified that X is a knave, and if that's all that ever happens then again we're done in $N+1$ questions. If at some point they say "yes" then we have found a non-knave. We can then ask that person two questions to figure out exactly what they are and (if they're a spy) what their "phase" is, and then proceed as above, asking them about everyone else in turn.







            In the worst case: we take two questions to establish that #1 is a knave; we take one more question to establish that #2 is knot a knave; we take two questions to establish that #2 is a spy and phind his phase; we then have $N-2$ people to figure out, divide them into $leftlceilfrac{N-2}3rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfrac{N-2}3rightrceil+5$ questions. I make no claim that this is optimal, though.







            share|improve this answer











            $endgroup$



            Wrong answer



            [EDITED to add:] Oops, the following is all wrong; thanks to @hexomino for pointing out in comments that I misinterpreted the question. I'm leaving this here rather than deleting it because (1) it's possible that some idea in it is salvageable and (2) I don't believe in making myself look better by deleting my mistakes :-). (I might delete it later to reduce clutter.)



            The minimal number of questions




            is less than $2N$, at least when $N$ is not too small. In fact, it's never more than $frac43N$ plus a few.




            Here's why.




            First, use two "are you a spy?" questions to establish what #1 is, and also (if they're a spy) which way around their truth-telling and lying answers are. We now have three cases. If #1 is a knight then we can just ask them about everyone else, and we're done in $N+1$ questions. If #1 is a spy then we ask them about everyone else -- once, asking "what is X?", when they are telling the truth, and twice, asking binary questions, when they are lying. Every 4 questions we find out about 3 people, so we take approximately $frac43N$ questions.







            The hardest case is when #1 is a knave. Here's one way to proceed. Ask them "is X a knave?" about each other person in turn. If they say "no" then we have correctly identified that X is a knave, and if that's all that ever happens then again we're done in $N+1$ questions. If at some point they say "yes" then we have found a non-knave. We can then ask that person two questions to figure out exactly what they are and (if they're a spy) what their "phase" is, and then proceed as above, asking them about everyone else in turn.







            In the worst case: we take two questions to establish that #1 is a knave; we take one more question to establish that #2 is knot a knave; we take two questions to establish that #2 is a spy and phind his phase; we then have $N-2$ people to figure out, divide them into $leftlceilfrac{N-2}3rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfrac{N-2}3rightrceil+5$ questions. I make no claim that this is optimal, though.








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 hours ago

























            answered 2 hours ago









            Gareth McCaughanGareth McCaughan

            68.3k3173267




            68.3k3173267








            • 1




              $begingroup$
              I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
              $endgroup$
              – hexomino
              2 hours ago










            • $begingroup$
              oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
              $endgroup$
              – Gareth McCaughan
              2 hours ago














            • 1




              $begingroup$
              I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
              $endgroup$
              – hexomino
              2 hours ago










            • $begingroup$
              oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
              $endgroup$
              – Gareth McCaughan
              2 hours ago








            1




            1




            $begingroup$
            I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
            $endgroup$
            – hexomino
            2 hours ago




            $begingroup$
            I think if #1 is a knight we still need 2N-2 questions because you can only ask questions like "Is A_j a knight?" not "What is A_j?" meaning that in the worst case you would still need two questions to determine each one, right?
            $endgroup$
            – hexomino
            2 hours ago












            $begingroup$
            oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
            $endgroup$
            – Gareth McCaughan
            2 hours ago




            $begingroup$
            oh, damn, I misread the question. You're right; we don't get to ask "what is X?" questions at all.
            $endgroup$
            – Gareth McCaughan
            2 hours ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Puzzling Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fpuzzling.stackexchange.com%2fquestions%2f83179%2fisland-of-knights-knaves-and-spies%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Le Mesnil-Réaume

            Ida-Boy-Ed-Garten

            web3.py web3.isConnected() returns false always