Card game rigging











up vote
8
down vote

favorite












You and your friend are playing a game with a deck of cards numbered 1 to N.



You will first put the deck of cards in whatever order you want. Next your friend will choose an option: "A" or "B". Finally, you will give your friend each card of the deck in order. For each card, your friend may either choose to keep it or discard it.



If they chose "A", your friend can only keep a card if it has a smaller number than the last card they kept. If they chose "B", they can only keep a card if it has a greater number than the last card they kept.



You know your friend is a cheater, and they know the order of the cards beforehand. How should you order the cards so your friend keeps the least # of cards possible?



Example:



There are 3 cards. Then you should order them 3, 1, 2. There is no option with better answer.



Source: COCI '14 Contest 6 #4 Kratki



Hint:




The answer for 9 cards is 3











share|improve this question
























  • I was about to type an answer, but then I realized I had missed a rule aout discarding.
    – Weckar E.
    Nov 26 at 23:12















up vote
8
down vote

favorite












You and your friend are playing a game with a deck of cards numbered 1 to N.



You will first put the deck of cards in whatever order you want. Next your friend will choose an option: "A" or "B". Finally, you will give your friend each card of the deck in order. For each card, your friend may either choose to keep it or discard it.



If they chose "A", your friend can only keep a card if it has a smaller number than the last card they kept. If they chose "B", they can only keep a card if it has a greater number than the last card they kept.



You know your friend is a cheater, and they know the order of the cards beforehand. How should you order the cards so your friend keeps the least # of cards possible?



Example:



There are 3 cards. Then you should order them 3, 1, 2. There is no option with better answer.



Source: COCI '14 Contest 6 #4 Kratki



Hint:




The answer for 9 cards is 3











share|improve this question
























  • I was about to type an answer, but then I realized I had missed a rule aout discarding.
    – Weckar E.
    Nov 26 at 23:12













up vote
8
down vote

favorite









up vote
8
down vote

favorite











You and your friend are playing a game with a deck of cards numbered 1 to N.



You will first put the deck of cards in whatever order you want. Next your friend will choose an option: "A" or "B". Finally, you will give your friend each card of the deck in order. For each card, your friend may either choose to keep it or discard it.



If they chose "A", your friend can only keep a card if it has a smaller number than the last card they kept. If they chose "B", they can only keep a card if it has a greater number than the last card they kept.



You know your friend is a cheater, and they know the order of the cards beforehand. How should you order the cards so your friend keeps the least # of cards possible?



Example:



There are 3 cards. Then you should order them 3, 1, 2. There is no option with better answer.



Source: COCI '14 Contest 6 #4 Kratki



Hint:




The answer for 9 cards is 3











share|improve this question















You and your friend are playing a game with a deck of cards numbered 1 to N.



You will first put the deck of cards in whatever order you want. Next your friend will choose an option: "A" or "B". Finally, you will give your friend each card of the deck in order. For each card, your friend may either choose to keep it or discard it.



If they chose "A", your friend can only keep a card if it has a smaller number than the last card they kept. If they chose "B", they can only keep a card if it has a greater number than the last card they kept.



You know your friend is a cheater, and they know the order of the cards beforehand. How should you order the cards so your friend keeps the least # of cards possible?



Example:



There are 3 cards. Then you should order them 3, 1, 2. There is no option with better answer.



Source: COCI '14 Contest 6 #4 Kratki



Hint:




The answer for 9 cards is 3








strategy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 at 16:25

























asked Nov 26 at 15:45









sunny-lan

2076




2076












  • I was about to type an answer, but then I realized I had missed a rule aout discarding.
    – Weckar E.
    Nov 26 at 23:12


















  • I was about to type an answer, but then I realized I had missed a rule aout discarding.
    – Weckar E.
    Nov 26 at 23:12
















I was about to type an answer, but then I realized I had missed a rule aout discarding.
– Weckar E.
Nov 26 at 23:12




I was about to type an answer, but then I realized I had missed a rule aout discarding.
– Weckar E.
Nov 26 at 23:12










3 Answers
3






active

oldest

votes

















up vote
13
down vote



accepted










I think you can get the bound down to




$lceil sqrt{N} rceil$, that is the square root of $N$, rounded up.




In the following way




Order the cards from $1$ to $N$ and partition them into $left[ frac{N}{lceil sqrt{N} rceil} right]$ subsets of size $lceil sqrt{N} rceil$ plus one additional subset of the leftovers (may have size zero). Then, reverse the order of the cards within each subset.

For example for $N=18$, we divide the cards into $3$ subsets of size $5$ and one of size $3$, i.e, $$ 1,2,3,4,5|6,7,8,9,10|11,12,13,14,15|16,17,18$$ then reverse the cards within each subset $$5,4,3,2,1|10,9,8,7,6|15,14,13,12,11|18,17,16$$ Then our maximum increasing or decreasing subsequence has size $5$.

For $N=9$ the corresponding ordering is $3,2,1,6,5,4,9,8,7$ which indeed has its longest increasing or decreasing subsequence with size $3$.




Why this works




To obtain an decreasing subsequence (option A) your friend must choose all of their cards to be within one of the partitions above (as cards between partitions are in increasing order). This gives them a maximum of $lceil sqrt{N} rceil$. On the other hand, if they choose option B, then all the cards they pick must be in different partitions as defined above, which gives them a maximum of $left[ frac{N}{lceil sqrt{N} rceil} right] leq frac{N}{lceil sqrt{N} rceil} leq lceil sqrt{N} rceil$. I think this is the best we can do while balancing the advantages of the two options.







share|improve this answer























  • That is the right answer, but I think you might be able to offer a stronger proof
    – sunny-lan
    Nov 26 at 17:43










  • Thanks, do you mean proving that this is a lower bound?
    – hexomino
    Nov 26 at 17:49










  • yeah, instead of saying its balanced
    – sunny-lan
    Nov 26 at 23:09


















up vote
5
down vote













There is actually a theorem which basically says that hexomino's solution is optimal. The name is




Erdős–Szekeres theorem.







share|improve this answer








New contributor




Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    2
    down vote













    Maybe I'm missing something, but




    Put the cards 1..N/2 in increasing order, and N..N/2+1 in decreasing order. The friend gets at most N/2 cards (rounded down).


    For example, with N=9:

    1, 2, 3, 4, 9, 8, 7, 6, 5
    The friend gets either 8, 7, 6 and 5 (option A) or 2, 3, 4 and 9 (option B).


    With N=8:

    1, 2, 3, 4, 8, 7, 6, 5

    The friend gets either 7, 6 and 5 (option A) or 2, 3, 4 and 8 (option B).







    share|improve this answer

















    • 1




      Good answer, but you can do better
      – sunny-lan
      Nov 26 at 16:20











    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    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',
    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%2f75756%2fcard-game-rigging%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    13
    down vote



    accepted










    I think you can get the bound down to




    $lceil sqrt{N} rceil$, that is the square root of $N$, rounded up.




    In the following way




    Order the cards from $1$ to $N$ and partition them into $left[ frac{N}{lceil sqrt{N} rceil} right]$ subsets of size $lceil sqrt{N} rceil$ plus one additional subset of the leftovers (may have size zero). Then, reverse the order of the cards within each subset.

    For example for $N=18$, we divide the cards into $3$ subsets of size $5$ and one of size $3$, i.e, $$ 1,2,3,4,5|6,7,8,9,10|11,12,13,14,15|16,17,18$$ then reverse the cards within each subset $$5,4,3,2,1|10,9,8,7,6|15,14,13,12,11|18,17,16$$ Then our maximum increasing or decreasing subsequence has size $5$.

    For $N=9$ the corresponding ordering is $3,2,1,6,5,4,9,8,7$ which indeed has its longest increasing or decreasing subsequence with size $3$.




    Why this works




    To obtain an decreasing subsequence (option A) your friend must choose all of their cards to be within one of the partitions above (as cards between partitions are in increasing order). This gives them a maximum of $lceil sqrt{N} rceil$. On the other hand, if they choose option B, then all the cards they pick must be in different partitions as defined above, which gives them a maximum of $left[ frac{N}{lceil sqrt{N} rceil} right] leq frac{N}{lceil sqrt{N} rceil} leq lceil sqrt{N} rceil$. I think this is the best we can do while balancing the advantages of the two options.







    share|improve this answer























    • That is the right answer, but I think you might be able to offer a stronger proof
      – sunny-lan
      Nov 26 at 17:43










    • Thanks, do you mean proving that this is a lower bound?
      – hexomino
      Nov 26 at 17:49










    • yeah, instead of saying its balanced
      – sunny-lan
      Nov 26 at 23:09















    up vote
    13
    down vote



    accepted










    I think you can get the bound down to




    $lceil sqrt{N} rceil$, that is the square root of $N$, rounded up.




    In the following way




    Order the cards from $1$ to $N$ and partition them into $left[ frac{N}{lceil sqrt{N} rceil} right]$ subsets of size $lceil sqrt{N} rceil$ plus one additional subset of the leftovers (may have size zero). Then, reverse the order of the cards within each subset.

    For example for $N=18$, we divide the cards into $3$ subsets of size $5$ and one of size $3$, i.e, $$ 1,2,3,4,5|6,7,8,9,10|11,12,13,14,15|16,17,18$$ then reverse the cards within each subset $$5,4,3,2,1|10,9,8,7,6|15,14,13,12,11|18,17,16$$ Then our maximum increasing or decreasing subsequence has size $5$.

    For $N=9$ the corresponding ordering is $3,2,1,6,5,4,9,8,7$ which indeed has its longest increasing or decreasing subsequence with size $3$.




    Why this works




    To obtain an decreasing subsequence (option A) your friend must choose all of their cards to be within one of the partitions above (as cards between partitions are in increasing order). This gives them a maximum of $lceil sqrt{N} rceil$. On the other hand, if they choose option B, then all the cards they pick must be in different partitions as defined above, which gives them a maximum of $left[ frac{N}{lceil sqrt{N} rceil} right] leq frac{N}{lceil sqrt{N} rceil} leq lceil sqrt{N} rceil$. I think this is the best we can do while balancing the advantages of the two options.







    share|improve this answer























    • That is the right answer, but I think you might be able to offer a stronger proof
      – sunny-lan
      Nov 26 at 17:43










    • Thanks, do you mean proving that this is a lower bound?
      – hexomino
      Nov 26 at 17:49










    • yeah, instead of saying its balanced
      – sunny-lan
      Nov 26 at 23:09













    up vote
    13
    down vote



    accepted







    up vote
    13
    down vote



    accepted






    I think you can get the bound down to




    $lceil sqrt{N} rceil$, that is the square root of $N$, rounded up.




    In the following way




    Order the cards from $1$ to $N$ and partition them into $left[ frac{N}{lceil sqrt{N} rceil} right]$ subsets of size $lceil sqrt{N} rceil$ plus one additional subset of the leftovers (may have size zero). Then, reverse the order of the cards within each subset.

    For example for $N=18$, we divide the cards into $3$ subsets of size $5$ and one of size $3$, i.e, $$ 1,2,3,4,5|6,7,8,9,10|11,12,13,14,15|16,17,18$$ then reverse the cards within each subset $$5,4,3,2,1|10,9,8,7,6|15,14,13,12,11|18,17,16$$ Then our maximum increasing or decreasing subsequence has size $5$.

    For $N=9$ the corresponding ordering is $3,2,1,6,5,4,9,8,7$ which indeed has its longest increasing or decreasing subsequence with size $3$.




    Why this works




    To obtain an decreasing subsequence (option A) your friend must choose all of their cards to be within one of the partitions above (as cards between partitions are in increasing order). This gives them a maximum of $lceil sqrt{N} rceil$. On the other hand, if they choose option B, then all the cards they pick must be in different partitions as defined above, which gives them a maximum of $left[ frac{N}{lceil sqrt{N} rceil} right] leq frac{N}{lceil sqrt{N} rceil} leq lceil sqrt{N} rceil$. I think this is the best we can do while balancing the advantages of the two options.







    share|improve this answer














    I think you can get the bound down to




    $lceil sqrt{N} rceil$, that is the square root of $N$, rounded up.




    In the following way




    Order the cards from $1$ to $N$ and partition them into $left[ frac{N}{lceil sqrt{N} rceil} right]$ subsets of size $lceil sqrt{N} rceil$ plus one additional subset of the leftovers (may have size zero). Then, reverse the order of the cards within each subset.

    For example for $N=18$, we divide the cards into $3$ subsets of size $5$ and one of size $3$, i.e, $$ 1,2,3,4,5|6,7,8,9,10|11,12,13,14,15|16,17,18$$ then reverse the cards within each subset $$5,4,3,2,1|10,9,8,7,6|15,14,13,12,11|18,17,16$$ Then our maximum increasing or decreasing subsequence has size $5$.

    For $N=9$ the corresponding ordering is $3,2,1,6,5,4,9,8,7$ which indeed has its longest increasing or decreasing subsequence with size $3$.




    Why this works




    To obtain an decreasing subsequence (option A) your friend must choose all of their cards to be within one of the partitions above (as cards between partitions are in increasing order). This gives them a maximum of $lceil sqrt{N} rceil$. On the other hand, if they choose option B, then all the cards they pick must be in different partitions as defined above, which gives them a maximum of $left[ frac{N}{lceil sqrt{N} rceil} right] leq frac{N}{lceil sqrt{N} rceil} leq lceil sqrt{N} rceil$. I think this is the best we can do while balancing the advantages of the two options.








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 26 at 17:26

























    answered Nov 26 at 16:42









    hexomino

    33.9k298161




    33.9k298161












    • That is the right answer, but I think you might be able to offer a stronger proof
      – sunny-lan
      Nov 26 at 17:43










    • Thanks, do you mean proving that this is a lower bound?
      – hexomino
      Nov 26 at 17:49










    • yeah, instead of saying its balanced
      – sunny-lan
      Nov 26 at 23:09


















    • That is the right answer, but I think you might be able to offer a stronger proof
      – sunny-lan
      Nov 26 at 17:43










    • Thanks, do you mean proving that this is a lower bound?
      – hexomino
      Nov 26 at 17:49










    • yeah, instead of saying its balanced
      – sunny-lan
      Nov 26 at 23:09
















    That is the right answer, but I think you might be able to offer a stronger proof
    – sunny-lan
    Nov 26 at 17:43




    That is the right answer, but I think you might be able to offer a stronger proof
    – sunny-lan
    Nov 26 at 17:43












    Thanks, do you mean proving that this is a lower bound?
    – hexomino
    Nov 26 at 17:49




    Thanks, do you mean proving that this is a lower bound?
    – hexomino
    Nov 26 at 17:49












    yeah, instead of saying its balanced
    – sunny-lan
    Nov 26 at 23:09




    yeah, instead of saying its balanced
    – sunny-lan
    Nov 26 at 23:09










    up vote
    5
    down vote













    There is actually a theorem which basically says that hexomino's solution is optimal. The name is




    Erdős–Szekeres theorem.







    share|improve this answer








    New contributor




    Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      5
      down vote













      There is actually a theorem which basically says that hexomino's solution is optimal. The name is




      Erdős–Szekeres theorem.







      share|improve this answer








      New contributor




      Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        5
        down vote










        up vote
        5
        down vote









        There is actually a theorem which basically says that hexomino's solution is optimal. The name is




        Erdős–Szekeres theorem.







        share|improve this answer








        New contributor




        Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        There is actually a theorem which basically says that hexomino's solution is optimal. The name is




        Erdős–Szekeres theorem.








        share|improve this answer








        New contributor




        Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Nov 27 at 3:26









        Viki

        511




        511




        New contributor




        Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Viki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






















            up vote
            2
            down vote













            Maybe I'm missing something, but




            Put the cards 1..N/2 in increasing order, and N..N/2+1 in decreasing order. The friend gets at most N/2 cards (rounded down).


            For example, with N=9:

            1, 2, 3, 4, 9, 8, 7, 6, 5
            The friend gets either 8, 7, 6 and 5 (option A) or 2, 3, 4 and 9 (option B).


            With N=8:

            1, 2, 3, 4, 8, 7, 6, 5

            The friend gets either 7, 6 and 5 (option A) or 2, 3, 4 and 8 (option B).







            share|improve this answer

















            • 1




              Good answer, but you can do better
              – sunny-lan
              Nov 26 at 16:20















            up vote
            2
            down vote













            Maybe I'm missing something, but




            Put the cards 1..N/2 in increasing order, and N..N/2+1 in decreasing order. The friend gets at most N/2 cards (rounded down).


            For example, with N=9:

            1, 2, 3, 4, 9, 8, 7, 6, 5
            The friend gets either 8, 7, 6 and 5 (option A) or 2, 3, 4 and 9 (option B).


            With N=8:

            1, 2, 3, 4, 8, 7, 6, 5

            The friend gets either 7, 6 and 5 (option A) or 2, 3, 4 and 8 (option B).







            share|improve this answer

















            • 1




              Good answer, but you can do better
              – sunny-lan
              Nov 26 at 16:20













            up vote
            2
            down vote










            up vote
            2
            down vote









            Maybe I'm missing something, but




            Put the cards 1..N/2 in increasing order, and N..N/2+1 in decreasing order. The friend gets at most N/2 cards (rounded down).


            For example, with N=9:

            1, 2, 3, 4, 9, 8, 7, 6, 5
            The friend gets either 8, 7, 6 and 5 (option A) or 2, 3, 4 and 9 (option B).


            With N=8:

            1, 2, 3, 4, 8, 7, 6, 5

            The friend gets either 7, 6 and 5 (option A) or 2, 3, 4 and 8 (option B).







            share|improve this answer












            Maybe I'm missing something, but




            Put the cards 1..N/2 in increasing order, and N..N/2+1 in decreasing order. The friend gets at most N/2 cards (rounded down).


            For example, with N=9:

            1, 2, 3, 4, 9, 8, 7, 6, 5
            The friend gets either 8, 7, 6 and 5 (option A) or 2, 3, 4 and 9 (option B).


            With N=8:

            1, 2, 3, 4, 8, 7, 6, 5

            The friend gets either 7, 6 and 5 (option A) or 2, 3, 4 and 8 (option B).








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 26 at 16:01









            jafe

            14.9k37149




            14.9k37149








            • 1




              Good answer, but you can do better
              – sunny-lan
              Nov 26 at 16:20














            • 1




              Good answer, but you can do better
              – sunny-lan
              Nov 26 at 16:20








            1




            1




            Good answer, but you can do better
            – sunny-lan
            Nov 26 at 16:20




            Good answer, but you can do better
            – sunny-lan
            Nov 26 at 16:20


















            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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.


            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%2f75756%2fcard-game-rigging%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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido