Quoto

Courses / Brainteaser patterns

Backward induction and games

9 cards3 min readBrainteasers

Card 1 of 9
  1. Idea: Start from the end

    Label each position winning or losing for the player to move, from size upward.

    • No moves left: losing, when the last item wins
    • Winning: some move leads to a losing position
    • Losing: every move leads to a winning position
  2. Formula: Take-away games

    With moves of 1 to k, the losing sizes are the multiples of k + 1; answer a move a with k + 1 − a.

  3. Example: 21 matches

    matches; each turn take , or ; whoever takes the last wins. Go first? How many do you take?

    1. Losing sizes are multiples of ; answer each with
    2. , so go first
    3. Leave : take
  4. Common mistake: Misreading who wins

    Using the same table when taking the last item loses. The losing sizes shift.

    Instead Then leave more than a multiple of , not a multiple. Read the winning rule twice.

  5. Idea: Unusual move sets

    The table works for any set of moves, even where no neat formula exists.

    • Moves , , : losing sizes , , , , ,
    • Remainder or on division by , as
    • Find the period by filling the table, never by guessing
  6. Quick check: Count the losing sizes

    With moves of , or , how many pile sizes from to are losing for the player to move?

    Show the answer

    Answer:

    Losing sizes leave remainder or on division by : from up to .

  7. Formula: Nim: the binary sum

    Add heap sizes in binary without carrying; the position is losing exactly when that sum is 0.

  8. Example: Heaps of 3, 4 and 5

    Nim with heaps , , : take any number from one heap; the last item wins. How many do you take?

    1. Binary , , : the sum is
    2. Flip the middle bit of : , which is
    3. Take from the first heap
  9. Idea: Say it in the room

    State the losing positions first, then the move that reaches one.

    • Take-away games: give the period and the reply rule
    • Nim: say the binary sums column by column
    • That column step is where slips happen