# Enigmatic Code

Programming Enigma Puzzles

## Enigma 480: An irrational question

From New Scientist #1631, 22nd September 1988 [link]

Kugelbaum was running through a geometrical proof with some of his students when he suddenly went off at a tangent.

“What an extraordinary rectangle I have just drawn!” he remarked out loud. “Why, the number of inches in the perimeter is an integer equal to the number of square inches in its area. And yet, no one of its sides is a rational number of inches long”. (A rational number is one which can be expressed as the ration of two definite integers: for example 1.5, but not √2).

What is the smallest possible perimeter of such a rectangle, measured in inches?

Happy Christmas from Enigmatic Code.

[enigma480]

### One response to “Enigma 480: An irrational question”

1. Jim Randell 24 December 2018 at 7:48 am

Suppose the rectangle has sides measuring x and y, and the perimeter and the area of the rectangle come to a whole number n.

Then we have:

2(x + y) = n
xy = n

Eliminating y from the equations gives us the quadratic equation:

2x² – nx + 2n = 0

which has roots at:

x = (n ± √(n(n – 16))) / 4

From which we see if 0 < n < 16 then the roots are complex.

At n = 16 we get: x = 4, y = 4

And at n = 17 we get: x = (17 ± √17) / 4, each root is irrational and corresponds to one side of the rectangle.

Setting: x = (17 + √17) / 4 and y = (17 – √17) / 4, we get:

xy = 17
2(x + y) = 17

as expected.

Solution: The smallest possible perimeter is 17 inches.

Here is a Python program based on the above analysis. It runs in 83ms.

Run: [ @repl.it ]

```from itertools import count
from enigma import is_square, printf

for n in count(1):
z = n * (n - 16)
r = is_square(abs(z))
if z < 0:
if r is None:
printf("n={n}: complex irrational roots, x = ({n} +/- sqrt({z})i) / 4", z=-z)
else:
printf("n={n}: complex rational roots, x = ({n} +/- {r}i) / 4")
else:
if r is None:
printf("n={n}: real irrational roots, x = ({n} +/- sqrt({z})) / 4")
break
else:
printf("n={n}: real rational roots, x = ({n} +/- {r}) / 4")
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.