GenerateRandomSearch

Train Track Puzzle Generator

A grid, two openings on its border, and a number beside every row and column saying how many of its squares carry track. Lay a single line of rails from one opening to the other, using straights and bends, so that every total comes out right. The line never crosses itself and never runs alongside itself — each square it passes through has exactly two ends, and that is the whole of the geometry. Every grid here is checked to have one answer, and you can ask for two dozen at once and print them as a booklet.

What this generator does

Walks a single line of rails from one border opening to another, counts the squares it uses in each row and column, then takes printed pieces away for as long as one layout still survives.

How to use this tool

  1. Choose a grid size and how many puzzles you want.
  2. Print the sheet, or copy the grids as text.
  3. Start where a total is 0, which empties a whole line, or where it equals the size of the grid, which fills one.
  4. Follow the line out from each opening; the piece at an opening is forced, and often so is the next.
  5. Show the answers to check, or print them separately for a booklet.

Understanding the controls

Grid
Five to nine squares a side. Nine is a measured ceiling and a close-run one — see how it is built, below.
How many
One to twenty-four, laid out one after another so the page prints as a booklet. Each is generated separately and checked separately.
Seed (optional)
Type anything to rebuild the same set later, which is how you reprint a booklet you have lost. A seed is deterministic and carries no cryptographic strength.

Common use cases

  • A booklet of puzzles to print for a holiday, a journey or a waiting room
  • A daily puzzle that takes ten minutes and needs no arithmetic beyond counting
  • A logic puzzle for someone who has tired of the number-placement kind
  • A classroom exercise in reading constraints off the edges of a grid
  • Reprinting the identical set later from its seed

How this generator works

The line is walked first, at random, from one opening on the border to another, never touching itself. The row and column totals are then simply counted off it. What follows is the thinning: every piece of track starts printed, and pieces are taken away one at a time for as long as a solver shown only the totals, the two openings and whatever pieces remain still finds a single answer. Very often that leaves nothing printed at all — measured, 25 of 40 grids at five a side need no printed pieces, because the totals and the openings pin the line down on their own. The solver's own economy comes from the rule that the track never loops: a join that would close a loop is refused as it is made, which is also what makes the finished line provably single, since a set of two-ended pieces with exactly two loose ends and no loop can only be one line.

Randomness and fairness

The line, the openings and the order pieces are removed in all come from your browser's cryptographic random source. Give a seed to get the same booklet back another day; a seed is for reproducibility, not cryptographic strength.

For how randomness is produced across the whole site, see how Generate Random works.

Limitations and good to know

  • The grid stops at nine squares a side. That is a measured limit and a close-run one: a nine takes six milliseconds at the median and 1,260 at the worst.
  • Ten and eleven are not offered because their worst cases cannot be trusted — one build at eleven a side took over five minutes among twenty that were instant.
  • Many grids end with no printed pieces at all, so two puzzles of the same size can be very unlike each other in difficulty.
  • Difficulty is not graded beyond the grid size, and the line is laid at random rather than shaped for an elegant solving path.

Privacy and your data

Every line is laid, thinned and checked in your browser. Nothing you type as a seed, and no puzzle made from it, leaves the device.