This classic problem from the Jiuzhang Suanshu (九章算术) is called Door and Pole (户与竿).

## Problem

Suppose there is a door height and width are unknown, and a bamboo pole of unknown length. When the pole is in the horizontal position, the excess length is 4 chi. When the pole is in the vertical position, the excess length is 2 chi. When the pole is in the diagonal position the pole fits through the door exactly. Question: What are the height, width, and the diagonal of the door?

## Solution

Let the width of the door be , the height of the door be , and the length of the pole be (diagonal of the door) be . The horizontal excess length is the gou-xian difference , and the vertical excess length is the gu-xian difference . The solution method given in the Jiuzhang Suanshu uses an interesting right-triangle identity: This formula can be derived using the above diagram, which takes advantage of the gou-xian difference and the gu-xian difference . Let the area of the gou-square be (red square), the area of the gu-square (green square), and the are of the xian-square . The yellow square at the center is the overlapping areas of the gou-square (red square) and the gu-square (green square); its area is . There are also two blue rectangles of equal area .

By inspection, one can deduce that subtracting the two blue rectangles from the entire square is equal in area to the sum of the red square with the green square minus the yellow square. By the Pythagorean theorem , we get Taking the square root gives Calculation

Height of the door:   Width of the door:   Diagonal of the door:   The width of the door is 6 chi; the height of the door is 8 chi; the length of the pole is 10 chi (1 zhang).