# Chapter 8: Rectangles

You have a grid of squares, with numbers written in some (but not all) of the squares. Your task is to subdivide the grid into rectangles of various sizes, such that (a) every rectangle contains exactly one numbered square, and (b) the area of each rectangle is equal to the number written in its numbered square.

Credit for this game goes to the Japanese puzzle magazine Nikoli [3]; I've also seen a Palm implementation at Puzzle Palace [4]. Unlike Puzzle Palace's implementation, my version automatically generates random grids of any size you like. The quality of puzzle design is therefore not quite as good as hand-crafted puzzles would be, but on the plus side you get an inexhaustible supply of puzzles tailored to your own specification.

[3] `http://www.nikoli.co.jp/en/puzzles/shikaku.html` (beware of Flash)

## 8.1 Rectangles controls

This game is played with the mouse or cursor keys.

Left-click any edge to toggle it on or off, or left-click and drag to draw an entire rectangle (or line) on the grid in one go (removing any existing edges within that rectangle). Right-clicking and dragging will allow you to erase the contents of a rectangle without affecting its edges.

Alternatively, use the cursor keys to move the position indicator around the board. Pressing the return key then allows you to use the cursor keys to drag a rectangle out from that position, and pressing the return key again completes the rectangle. Using the space bar instead of the return key allows you to erase the contents of a rectangle without affecting its edges, as above. Pressing escape cancels a drag.

When a rectangle of the correct size is completed, it will be shaded.

(All the actions described in section 2.1 are also available.)

## 8.2 Rectangles parameters

These parameters are available from the ‘Custom...’ option on the ‘Type’ menu.

Width, Height
Size of grid, in squares.
Expansion factor
This is a mechanism for changing the type of grids generated by the program. Some people prefer a grid containing a few large rectangles to one containing many small ones. So you can ask Rectangles to essentially generate a smaller grid than the size you specified, and then to expand it by adding rows and columns.

The default expansion factor of zero means that Rectangles will simply generate a grid of the size you ask for, and do nothing further. If you set an expansion factor of (say) 0.5, it means that each dimension of the grid will be expanded to half again as big after generation. In other words, the initial grid will be 2/3 the size in each dimension, and will be expanded to its full size without adding any more rectangles.

Setting an expansion factor of around 0.5 tends to make the game more difficult, and also (in my experience) rewards a less deductive and more intuitive playing style. If you set it too high, though, the game simply cannot generate more than a few rectangles to cover the entire grid, and the game becomes trivial.

Ensure unique solution
Normally, Rectangles will make sure that the puzzles it presents have only one solution. Puzzles with ambiguous sections can be more difficult and more subtle, so if you like you can turn off this feature and risk having ambiguous puzzles. Also, finding all the possible solutions can be an additional challenge for an advanced player. Turning off this option can also speed up puzzle generation.

[Simon Tatham's Portable Puzzle Collection, version 20170314.eedea41]