# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1594: Four points

From New Scientist #2759, 8th May 2010 [link]

I drew a square whose sides were an integral number (less than 80) of centimetres long. Within the top left-hand quarter of the square I marked four points, each of which was an integral number of centimetres, not only from each side of the square but also from both the top left-hand corner and the bottom right-hand corner of the square.

How long was each side of the square?

[enigma1594]

### One response to “Enigma 1594: Four points”

1. jimrandell 17 January 2012 at 10:26 pm

The following Python program runs in 35ms.

```from collections import defaultdict
from enigma import irange

# find squares (up to 80 * sqrt(2))
squares = {}
for i in irange(1, 113):
squares[i * i] = i

# find Pythagorean triples (x, y [, h]) such that x < y < 40
triples = dict()
for x in irange(1, 38):
for y in irange(x + 1, 39):
h2 = x * x + y * y
if h2 not in squares: continue
triples[(x, y)] = squares[h2]

# now consider a square of side n
ts = defaultdict(list)
for n in irange(1, 79):
n2 = float(n) / 2
for t in triples:
(x, y) = t
if not(y < n2): continue
# now see if (n - y, n - x) are valid triples
h2 = (n - y) * (n - y) + (n - x) * (n - x)
if h2 not in squares: continue
ts[n].extend((t, (n - y, n - x)))

for n in sorted(ts.keys()):
if len(ts[n]) < 4: continue
print(n, ts[n])
```

Solution: Each side of the square is 72 cm.

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