Walking back: machines that turn around

On Monday and Tuesday the head only moves right. From Wednesday on, some puzzles need it to walk to the end of the input first and do its work on the way back. This page is about why, and how to tell the two kinds apart.

What a right-only machine knows

When the head is on a cell, a machine that only moves right has seen everything to the left of that cell and nothing to the right of it. It has to write the cell now, and it will never come back. So what it writes can depend on what came before, through its state, but never on what comes after.

That gives a test you can apply to any output. For each cell that changed, ask whether you could have decided it without looking further right. In "every B after the first becomes A" you can: when you reach a B, you already know whether you have passed one. In "the last B becomes A" you cannot: when you reach a B, you do not yet know whether another one follows.

Adding one

The standard example is adding one to a number written in binary. Read A as 0 and B as 1. Then ABB is 011, which is three, and adding one gives 100, which is four: BAA.

The method is the one from school arithmetic. Start at the right. While the digit is 1, write 0 and carry one to the left. At the first 0, write 1 and stop. If you run out of digits while still carrying, write a 1 in front.

Whether a digit changes depends only on the digits to its right. The first digit of 011 becomes 1 because both digits after it are 1; in 010 it would stay 0. A right-only machine reaches that first digit before it has seen the others, so it cannot get every input right. A machine that walks to the end first can, and it needs only two states.

This machine adds one. State 1 walks out to the blank, and state 2 carries on the way back.

State 1 walks right over the input without changing it and turns around at the blank. State 2 is the carry. Reading B, it writes A and keeps moving left, still carrying. Reading A, it writes B and stops on ✓. Reading the blank, which means it has run off the left end, it writes B there and stops.

StepStateReadsWritesMovesNextTape after
11AAright1ABB
21BBright1ABB
31BBright1ABB
41blankblankleft2ABB
52BAleft2ABA
62BAleft2AAA
72ABleft✓BAA

When every digit is 1, the carry runs off the left end, and the new digit goes on the blank cell there:

InputOutput
BBBBAAA
BBA
AB
ABABABBA

How walk-back puzzles are built

Turing Daily makes its walk-back puzzles in this same shape. State 1 walks right without changing anything and turns around at the blank. Its three cells are always the same: for A and for B, write the symbol back and move right; at the blank, move left into state 2. The other states then move left, changing cells, until one of them stops on ✓.

So on a medium or hard day:

  • If any given cell has an arrow pointing left, it is a walk-back puzzle and state 1 is the walk out. If one of state 1's cells is a ? cell, you already know its answer.
  • Read the outputs from the right. The changes start at the right end, and the question for each state is what it does while moving left, and when it hands over or stops.
  • Expect fewer ? cells. A walk-back puzzle leaves one cell fewer than a right-only puzzle on the same day: two on a medium day, three on a hard one.

Stopping early

Adding one stops as soon as the carry is used up. Nothing to the left of that point changes, so there is no reason to keep walking. Walk-back puzzles do the same: a ✓ cell partway through the walk back leaves the rest of the tape as it is. When the left part of every output matches its input, look for the cell where the machine stops.

Machines that walk more

A general Turing machine can turn around as often as it likes. It can go back to compare cells, cross things off and use the tape as working memory. Turing Daily puzzles turn around at most once, which keeps them small enough to hold in your head.