Island of Knights, Knaves and Spies Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraAbout the island of Knights and KnavesAbout Knights and Knaves and their consistencyThe way to Acarien, with Knights and KnavesIf The Knights and Knaves got togetherKnights , Knaves and Spies - Part 1Knights , Knaves and Spies - Part 2Meta Knights and Knaves Puzzle with HatsKnights, Knaves and Normals - the tough oneKnights Knaves and SpiesSolve the following knights and knaves problem

First instead of 1 when referencing

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

Why does Arg'[1. + I] return -0.5?

A Paper Record is What I Hamper

What does a straight horizontal line above a few notes, after a changed tempo mean?

Why must Chinese maps be obfuscated?

How to avoid introduction cliches

How do I reattach a shelf to the wall when it ripped out of the wall?

Which big number is bigger?

Multiple fireplaces in an apartment building?

When do you need buffers/drivers on buses in a microprocessor design?

How to not starve gigantic beasts

Scheduling based problem

Mistake in years of experience in resume?

Is this homebrew arcane communication device abusable?

How to find if a column is referenced in a computed column?

What is /etc/mtab in Linux?

Implementing 3DES algorithm in Java: is my code secure?

Is Diceware more secure than a long passphrase?

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Is Electric Central Heating worth it if using Solar Panels?

What was Apollo 13's "Little Jolt" after MECO?

Bayes factor vs P value

What is it called when you ride around on your front wheel?



Island of Knights, Knaves and Spies



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraAbout the island of Knights and KnavesAbout Knights and Knaves and their consistencyThe way to Acarien, with Knights and KnavesIf The Knights and Knaves got togetherKnights , Knaves and Spies - Part 1Knights , Knaves and Spies - Part 2Meta Knights and Knaves Puzzle with HatsKnights, Knaves and Normals - the tough oneKnights Knaves and SpiesSolve the following knights and knaves problem










5












$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
    4 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
    1 hour 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
    1 hour 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
    46 mins ago















5












$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
    4 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
    1 hour 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
    1 hour 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
    46 mins ago













5












5








5





$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 1 hour ago









Gareth McCaughan

68.3k3173267




68.3k3173267










asked 4 hours ago









trolley813trolley813

1,40648




1,40648











  • $begingroup$
    I take it we should assume that all the islanders know what everyone is?
    $endgroup$
    – Gareth McCaughan
    4 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
    1 hour 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
    1 hour 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
    46 mins ago
















  • $begingroup$
    I take it we should assume that all the islanders know what everyone is?
    $endgroup$
    – Gareth McCaughan
    4 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
    1 hour 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
    1 hour 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
    46 mins ago















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




$begingroup$
I take it we should assume that all the islanders know what everyone is?
$endgroup$
– Gareth McCaughan
4 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
1 hour 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
1 hour 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
1 hour 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
1 hour 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
46 mins 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
46 mins ago










2 Answers
2






active

oldest

votes


















2












$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 $leftlceilfracN-23rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfracN-23rightrceil+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
      1 hour 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
      1 hour 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









    2












    $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$

















      2












      $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$















        2












        2








        2





        $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 45 mins ago

























        answered 55 mins ago









        noednenoedne

        9,63312667




        9,63312667





















            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 $leftlceilfracN-23rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfracN-23rightrceil+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
              1 hour 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
              1 hour 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 $leftlceilfracN-23rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfracN-23rightrceil+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
              1 hour 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
              1 hour 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 $leftlceilfracN-23rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfracN-23rightrceil+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 $leftlceilfracN-23rightrceil$ groups of at most 3, and use 4 questions for each group, for a total of $leftlceilfracN-23rightrceil+5$ questions. I make no claim that this is optimal, though.








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 1 hour ago

























            answered 1 hour 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
              1 hour 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
              1 hour 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
              1 hour 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
              1 hour 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
            1 hour 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
            1 hour 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
            1 hour 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
            1 hour 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

            ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

            Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

            19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу