GenerateRandomSearch

Langford Sequence Generator

Dudeney's puzzle, rediscovered by Langford watching his son stack coloured blocks: arrange two each of the numbers 1 to n so that the two 1s have one thing between them, the two 2s have two, and so on. With three pairs there is exactly one answer. With five pairs there is none at all, and no amount of searching will help — the reason is a counting argument, and it rules out every count except those leaving remainder 0 or 3 when divided by four.

What this generator does

Places the largest pair first and works downwards, backtracking whenever a pair cannot fit, and reports plainly when the count is one for which no arrangement can exist.

How to use this tool

  1. Choose how many pairs to arrange.
  2. Search, and read the sequence.
  3. Check the spacing yourself: the two 4s should have four things between them.
  4. Try five or six pairs to see the impossibility reported.

Understanding the controls

How many pairs
Two to twelve. Only counts leaving remainder 0 or 3 on division by four can be arranged; the others are reported as impossible rather than searched in vain.

Common use cases

  • A short puzzle to set for a class or a club
  • Demonstrating that some puzzles fail for reasons of counting, not difficulty
  • Building blocks or cards for a hands-on version
  • Teaching backtracking with a small, satisfying search
  • Checking a sequence you have arranged yourself

How this generator works

The finished sequence is taken apart again: each number's two positions are located afresh, the gap between them is measured, and it must equal the number itself. Every place must also be filled and every number must appear exactly twice, so a sequence that is nearly right fails rather than passes.

Randomness and fairness

Nothing is random. The search runs in a fixed order, so the same count always gives the same sequence.

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

Limitations and good to know

  • Two to twelve pairs. Larger counts have astronomically many arrangements and finding one is not the interesting part.
  • One arrangement is shown, though there are many for larger counts — over 300,000 for twelve pairs.
  • Reversing a sequence gives another valid one, and the two are not listed separately.
  • Counts that leave remainder 1 or 2 on division by four have no arrangement at all.

Privacy and your data

The search runs in your browser and nothing is transmitted or stored.