Skip to content

Sunday Times Teaser 3167 – Binary Primes

by BRG on June 3, 2023

by Mark Valentine

Published Sunday June 04 2023 (link)

Grace and Helen play a turn-based card game. Each player is given two cards with a zero printed on them, and unlimited cards with a one printed on them. Before the game starts a 1 is placed on the table. Sitting on the same side of the table, a turn then involves placing a card to the left of the table cards, such that the value shown in binary remains prime or one (allowing leading zeros). The winner is the player who is last able to play a card, earning points equal to the value on the table at that time.

Being expert logicians, they play the best possible cards to maximise their points or minimise their opponent’s points. Grace goes first.

Who wins and with what cards on the table from left to right?

From → Uncategorized

14 Comments Leave one →
  1. BRG permalink

    • John Z permalink

      Brilliant!

      in line 12

      is redundant because cv can never be 0.
      in line 23

      is also redundant.

      • John Z permalink

        and line 16

      • BRG permalink

        Hi John,

        These (and other) conditions are there to ensure that the subroutine will work
        with other inputs, For example, calling it with no cards on the table at the start.

  2. Frits permalink

    I found this version of returning positive/negative points a bit more intuitive.

    • BRG permalink

      I have noticed that I can simplify mine a bit by altering what I store (which I will do shortly).

  3. Frits permalink

    Without recursion.

    First all possible games are determined and then the whole list of games is collapsed to only one entry (working our way back from games with the most moves to games with the fewest moves)

    • Frits permalink

      Line 30 must be:

  4. John Z permalink

    This code prints out all possible outcomes without indicating which is the solution to the teaser. The ‘0’ card count switch is inspired by Brian’s code.

    • Frits permalink

      Hi John, why is sorting necessary? I find it difficult to see order in the output.

      The contents of games and list(zerone()) are the same.

  5. John Z permalink

    Hi frits, The purpose of sorting is to place games with the same initial plays next to each other so that the tree of plays is easier to visualise or draw manually.

  6. John Z permalink

    Frits, you are absolutely right, there is no need to sort because the result of zerone() is already in the desired order. Thanks. Here is the slimmed down version…

  7. Frits permalink

    Starting from a list of prime numbers. I can’t deduce an upper limit for the highest prime number.

    (in my previous program I conclude who wins based on the printed entries).

  8. BRG permalink

    For interest here is a version based on the bottom up pruning of a binary tree. To show the pruning process, set ‘print_tree’ to True.

Leave a Reply

Note: HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS