GenerateRandomSearch

Stitches Puzzle Generator

A Stitches grid is cut into irregular blocks, and the job is to sew them together. Every two blocks that share a border must be joined by one stitch — a short line across the border from a square on one side to the square next to it on the other — and each end of a stitch leaves a hole. No square may have more than one hole, and the numbers along the top and down the side say how many holes each column and row contains. That is the whole puzzle, and it solves by counting: a row whose number is zero rules out every border that crosses it, and a border with only one place left has to be stitched there. This makes a fresh grid at the size you choose and prints it only once a search of the printed numbers has found exactly one answer.

What this generator does

Cuts a square grid into blocks of roughly equal size, draws one valid stitching, prints the hole counts that stitching produces, and then solves the printed puzzle from nothing to confirm no second stitching fits the same numbers. What sets it apart from the other puzzles here is what you are placing. In Bridges you join numbered islands and each island says how many bridges it carries; in Tents and Trees each tree gets a tent in a neighbouring square; in Dominosa you pair up neighbouring squares by the values printed in them. Here nothing is printed inside the grid at all. The unknown is a set of joins across the borders between blocks, exactly so many per pair of blocks, and the only numbers are the totals at the edge.

How to use this tool

  1. Choose the size of the grid, and whether touching blocks are joined by one stitch or two.
  2. Choose how many blocks the grid is cut into — more blocks means more borders to stitch.
  3. Press the button. The blocks are drawn with heavy lines and the numbers sit above and beside the grid.
  4. Work out where each stitch goes, starting from the rows and columns whose numbers are smallest or largest.
  5. Press Show the answer to check, or print the puzzle; the answer prints on a second page only if it is showing.

Understanding the controls

Grid
Five to ten squares a side. The count of stitches rises with it — the standard five-square puzzle has around seven and the standard ten-square one around nineteen — but a larger grid also gives each border more places a stitch could go, so there is more to eliminate per stitch as well as more stitches.
Stitches per border
One stitch between each pair of touching blocks, or two. Two is the harder form and a different puzzle to solve: every border has to be long enough to take two stitches, and a block needs a square for every hole its borders demand, so the blocks are larger and fewer.
Blocks
How many blocks the grid is cut into. More blocks means more pairs of them touching, and so more stitches to place. Only some counts are offered at each size, and the limit is measured, not chosen: push the count up and most layouts cannot be stitched at all, because small blocks have more neighbours than squares. On an eight-square grid, ten blocks produced a usable puzzle from only nine layouts in a hundred.
Seed (optional)
Type anything and the same settings give the same puzzle again. The work is counted in search steps, never in time, so a seed gives the same grid on a slow machine as on a fast one. It is for getting a puzzle back; a seed is not cryptographic and is not a way of keeping a puzzle secret.

Worked examples

Six squares, one stitch per border, standard blocks — seed rainy-day
Six blocks with ten pairs of them touching, so ten stitches and twenty holes. Columns 2 4 4 2 4 4; rows 2 1 5 4 5 3. The second row's single hole is the way in: only one stitch can reach into that row. This was the fourth layout drawn — the first three had no stitching or more than one.
Seven squares, two stitches per border — seed rainy-day
Four blocks, five borders, ten stitches. Columns 0 2 4 4 3 6 1; rows 2 4 5 1 4 3 1. The first column holds no holes at all, which removes every stitch that would cross it before the puzzle has started.
Ten squares, one stitch per border — seed rainy-day
Ten blocks, twenty borders, twenty stitches. Columns 0 3 9 4 6 3 3 8 2 2; rows 0 4 4 6 2 7 6 4 4 3. The third column takes nine holes out of ten squares, so almost all of it is known at once.

Common use cases

  • A printed logic puzzle for somebody who has had enough of sudoku and wants a rule set they have not met
  • An extension task that runs on counting and elimination, with no arithmetic beyond adding up to a row total
  • A set of puzzles of rising size for a puzzle club, from a five-square grid with four stitches to a ten-square one with twenty
  • Getting the same puzzle back later from its seed, to print a second copy or to check an answer

How this generator works

The blocks are grown from scattered starting squares, always extending whichever block is currently smallest, which keeps them close to the same size. That matters more than it sounds. Blocks grown unevenly leave slivers of one or two squares that touch three or four neighbours, and a square can only hold one hole, so such a layout cannot be stitched however the numbers are set; a layout is thrown out before any stitching is tried if some block has more holes to hold than squares to hold them. A stitching is then drawn by a search that settles the borders with the fewest possible places first, choosing among the places at random. The numbers are counted from that stitching. Then comes the step that makes it a puzzle: the same search is run again on the printed grid and numbers alone, with no knowledge of the answer, and told to stop at a second solution. If it finds one, the layout is discarded and another is drawn. That happens often — on the standard eight-square grid about a third of stitchable layouts give numbers that fit two different stitchings — so a grid that reaches the page is one that passed, not one that was assumed to. The rules themselves are checked separately from the search: the answer is re-read square by square, recounting the holes in every row and column and the stitches across every border.

Randomness and fairness

Chance decides where each block starts, which square it grows into, and which of the available places each stitch takes. The numbers at the edge are counted from the result and involve no further draw. Layouts that cannot be stitched, or whose numbers allow two answers, are thrown away, so the puzzles you see are not an even sample of all possible grids — they are the ones with a single answer. The draws come from your browser's cryptographic random source unless a seed is given, which swaps in a repeatable source for reproducibility, not secrecy.

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

Limitations and good to know

  • One or two stitches per border. The three-stitch form was measured on these grids and only produces a puzzle when the grid is cut into three blocks, which leaves two or three borders — too few to be worth solving — until the grid reaches ten squares.
  • The largest grid is ten squares a side. Published collections go to fifteen, and those are not made here.
  • The answer is shown complete. The page does not walk through the order in which the stitches can be deduced, and it does not grade a puzzle as easy or hard; the size, the number of blocks and the stitches per border are the only levers.
  • Blocks are kept close to equal in size, because uneven ones usually cannot be stitched. Long thin blocks that wind across the grid, which a human setter might draw on purpose, do not appear.
  • Puzzles with a single answer are kept and the others thrown away, so some shapes of grid turn up more often than others. Nothing here is a uniform sample of every possible Stitches puzzle.

Common mistakes

Stitching blocks that only meet at a corner
Blocks touch only if two of their squares share a full edge. Two blocks that meet corner to corner have no border and are not joined.
Counting stitches against the numbers at the edge
The numbers count holes, and a stitch has two. A stitch lying along a row puts two holes in that row and one in each of two columns; one crossing between rows puts one hole in each row and two in a single column.
Placing a second stitch between two blocks because there is room
The quota is exact. With one stitch per border, two blocks that already have their stitch take no more, however long the border between them is.

Practical tips

  • Mark the squares that cannot hold a hole first — every square in a row or column numbered zero, and the rest of a row once its number is used up.
  • Look for short borders. Two blocks that share only one edge have their stitch decided before any counting.
  • Count the pairs of touching blocks before starting: that is how many stitches there are, and twice that is what the row numbers must add up to.

Privacy and your data

The grid is drawn, stitched and solved entirely in your browser. The only thing you can type is a seed, and it is not stored, not sent anywhere and not included in any usage count.

Frequently asked questions

What are the rules of Stitches?
The grid is divided into blocks. Join every pair of blocks that share a border with exactly the stated number of stitches — one, in the usual form. A stitch is a straight join between two squares that share an edge and belong to different blocks, and it leaves a hole in each. No square may contain more than one hole. The number outside each row and column is the number of holes in it.
How do I start one?
With the extremes. A row or column numbered zero contains no holes, so no stitch touches it and every border that could only be stitched there is settled elsewhere. A row whose number equals the number of squares in it is full. After that, find borders with few places left: two blocks that touch along a single edge must be stitched across that edge, and that stitch uses up two holes from the counts.
How do you know there is only one answer?
By solving it. After the puzzle is made, a search works from the blocks and the printed numbers alone and looks for two different stitchings; the puzzle is only kept if it finds exactly one. The search was itself checked on small grids by trying every possible set of stitches and comparing the totals.
Why can't I choose more blocks?
Because past a point the grid cannot be stitched. A block needs a separate square for each of its neighbours, and small blocks run out. Cutting a five-square grid into seven blocks gave a usable puzzle from about one layout in a hundred; at five blocks it is more than half. The counts offered are the ones where at least about one layout in five works.