Rafters

The sloping beams that hold a roof up have to go somewhere, and that is the choice you are given. How many you place is decided before the puzzle starts; only which positions they take is yours.

How to play

Two corners make a beam: tap one, then the other, and tap the same pair again to take it down.

  1. Count what you need Three fewer rafters than the hall has corners, always. The counter tells you how many are up.
  2. Look for short spans Two corners close together with one between them make a cheap triangle. Cut those off first.
  3. Work inwards Each rafter divides the hall into two smaller halls, and each of those is the same problem again.
Full instructions

In depth

How to solve the Rafters roof bracing puzzle

Rafters is a puzzle about triangulating a polygon. You are shown an irregular but convex hall viewed from above, and your job is to brace it entirely into triangles by running rafters from corner to corner. A triangle cannot be pushed out of shape, which is why the whole roof must be made of them. The catch is that every rafter costs its own length in timber, and you want the cheapest bracing possible. This guide covers the rules, the controls, the geometry behind the puzzle, and the strategy that leads to the least timber.

Screenshot: How to play Rafters
How to play Rafters as it appears when the page opens.

Rules and objective

The hall is a convex polygon with a set number of corners. You must divide it entirely into triangles by drawing rafters between corners. A rafter is a straight line from one corner to another that cuts across the inside of the hall. It may not run along a wall, because the walls are already there. Two rafters may not cross each other, because overlapping beams would not divide the hall into clean triangles.

The number of rafters you need is always fixed: three fewer than the number of corners. A six-cornered hall needs three rafters. An eight-cornered hall needs five. This is a basic fact of geometry and it never changes, regardless of which corners you connect. What does change is the total length of timber used, because rafters between nearby corners are short and rafters spanning the whole hall are long. Your goal is to find the set of rafters that uses the least timber.

Controls and how to play

Tap one corner to select it, then tap another corner to run a rafter between them. If the rafter is valid, it appears on the plan. If it would cross an existing rafter, the game refuses and tells you why. Tapping the same pair of corners again removes the rafter, so you can undo a mistake without starting over. Tapping the same corner twice deselects it.

The stats bar shows three numbers: the count of rafters placed out of the total needed, the timber used so far, and the least timber possible. The target figure is calculated exactly using a technique that tests every possible way to split each stretch of wall and keeps the cheapest combination. When your total timber matches or beats that figure and all triangles are in place, you win.

The Hall selector offers three sizes. Small uses six corners, which gives fourteen possible bracings. Medium uses eight corners with one hundred and thirty-two possible bracings. Large uses ten corners, where the count reaches four thousand eight hundred and sixty-two. Press New game to generate a fresh hall at the selected size.

Why triangles cannot be pushed out of shape

A triangle is rigid. Once you fix the lengths of its three sides, its shape is determined. A square or any other four-sided shape can be deformed into a parallelogram by pushing on one corner, because fixing four side lengths does not fix the angles. This is why roof trusses, bridge frames, and tower structures are all built from triangles.

In this puzzle, the hall is a single polygon that can flex at its corners. By dividing it into triangles, you make every piece rigid, and the whole structure locks into place. That is the point of the bracing, and it is why any valid solution must cover every part of the hall with triangles, not quadrilaterals or larger shapes.

The short-span strategy

The cheapest bracings almost always start at the edges. Look for two corners that are close together with one corner between them. Drawing a rafter from the first to the third cuts off a small triangle, and that triangle costs only the length of the rafter itself because the two walls are free. Once you have cut off that triangle, the remaining hall has one fewer corner and is a slightly simpler problem.

Work inward from the cheapest triangles first. Each rafter divides the hall into two smaller halls, and each of those is the same problem again. If both halves have short spans available, take those next. By the time you reach the last rafter, the remaining polygon is a triangle and the rafter is forced.

Avoiding long spans

A rafter that spans the full width of the hall is expensive and often forces more expensive rafters on either side. If the hall has ten corners and you draw a rafter from corner one to corner six, you have split it into two five-cornered halls. Each of those needs two more rafters, and the internal distances may be large because the split was so wide.

Long rafters are not always wrong, but they should be a last resort. If the only way to reach the least-timber figure involves one long rafter, it will be because the short rafters on either side of it are cheap enough to compensate. As a general rule, keep every rafter as short as you can and only stretch across the hall when no shorter option remains.

How the least-timber figure is calculated

The game finds the optimal bracing using dynamic programming. It considers every stretch of consecutive corners around the wall. For each stretch of three or more corners, it asks: which corner in the middle should form a triangle with the two endpoints? The cost of that triangle is the cost of the two new rafters plus the cost of bracing each side optimally. By starting with the shortest stretches and building up to the whole hall, the search covers every possible bracing without trying them one at a time.

This approach works because the best bracing for the whole hall is built from the best bracings of its pieces. You can borrow the same idea in your head. Look at a stretch of four or five corners and ask which triangle you would cut off first. Check the cost and compare it with cutting off a triangle from the other end. The cheaper choice is usually the right one.

Common mistakes beginners make

The most common mistake is drawing rafters without a plan. Players tap two corners at random, see a rafter appear, and repeat until the hall is full of triangles. This almost never produces the cheapest bracing, because the first few rafters constrain what is possible later. A long rafter placed early can force every subsequent rafter to be long as well.

Another frequent error is trying to make all the triangles roughly the same size. Equal-sized triangles look satisfying, but the cheapest bracing usually has a mix of small triangles near the short walls and larger ones in the middle. The goal is minimum timber, not visual symmetry.

Beginners also forget that removing a rafter is free. If you are three rafters in and the timber is already above the target, tap the offending rafter pair to remove it and try a different path. There is no penalty for undoing a rafter, and a fresh approach often saves a large amount of timber.

Difficulty levels and Catalan numbers

The number of distinct bracings of a polygon is a Catalan number, first counted by Euler in 1751. Six corners give fourteen bracings. Eight corners give one hundred and thirty-two. Ten corners give four thousand eight hundred and sixty-two. The growth is dramatic, and by twenty corners the count is in the billions.

On Small, fourteen bracings is a manageable number, and you could try a few by hand to find the cheapest. On Medium, one hundred and thirty-two is too many to try by hand but the puzzle is still solvable with the short-span strategy. On Large, the count runs into thousands and you have to rely on the principle of cutting off cheap triangles first. The least-timber figure shown is always exact, so you know you have found the best bracing when your total matches it.

Privacy and how the puzzle runs

The entire puzzle runs inside your browser. No data is sent to a server, there is no account to create, and your best score is stored in local storage on this device only. Nothing is uploaded at any point, and no personal information is collected. Once the page has loaded, the game works fully offline without any connection needed.

Help

How to play Rafters

Two corners make a beam: tap one, then the other, and tap the same pair again to take it down. Beams may not cross one another and may not lie along a wall, which leaves the diagonals across the hall as the only useful lines. The hall is braced when every bay has been broken into triangles.

Count what you need

Three fewer rafters than the hall has corners, always. The counter tells you how many are up.

Look for short spans

Two corners close together with one between them make a cheap triangle. Cut those off first.

Work inwards

Each rafter divides the hall into two smaller halls, and each of those is the same problem again.

Avoid the long way across

A rafter spanning the whole hall is expensive and often forces two more.

Catalan numbers, and why the search is short anyway

The number of ways to cut a polygon into triangles with non-crossing diagonals is a Catalan number, and Euler worked out the count in 1751 — arguably the first time anyone had counted them. They grow fast: 14 for a hexagon, 132 for an octagon, 16,796 for a twelve-sided hall, and 1,767,263,190 for twenty-two sides. Trying them all is hopeless almost immediately. Finding the cheapest is nonetheless quick, because of a simple observation: the wall from one corner round to another is closed off by exactly one triangle, and whatever lies either side of that triangle is a smaller version of the same question. Work outwards from the short spans, remember each answer, and the whole thing takes a few thousand steps rather than a few billion. The same trick — a problem whose best answer is built from the best answers to its pieces — is behind a great deal of what computers do quickly.

Good to know

Triangles are the point

A four-sided panel can be pushed out of square. A triangle cannot, which is why the whole roof has to be made of them.

The count never changes

Whatever you do you will end with the same number of rafters and the same number of triangles. Only the timber differs.

Crossing is refused

Two rafters through the same air is not a roof. The board will not let you.

The count of bracings is enormous

Six corners give 14 ways, eight give 132, twelve give 16,796. The board counts yours and says so.

Common questions

How many rafters will I use?
Three fewer than the number of corners, every time, whatever route you take.
Can a rafter run along a wall?
No. The walls are already there; a rafter must cut across the hall.
Why can rafters not cross?
Because they would not divide the hall into triangles. Only non-crossing bracings count.
Is the least-timber figure exact?
Yes — worked out by building up the best bracing for every stretch of wall.
Is the hall always convex?
Yes, so every rafter between two corners stays inside it.