# Enigmatic Code

Programming Enigma Puzzles

## Enigma 958: Three churches

From New Scientist #2113, 20th December 1997 [link]

In George’s small home town there are three churches, equidistant from each other as the crow flies — that is to say, the stand at the vertices of an equilateral triangle. George is standing exactly 1 mile in a straight line from one church, 5/8 mile from the second and just 3/8 mile from the third.

Exactly how far apart are the churches from each other?

[enigma958]

### One response to “Enigma 958: Three churches”

1. Jim Randell 29 May 2020 at 9:12 am

See: Enigma 278.

If George’s distances from the churches are a, b, c, and the churches are a distance s from each other, we have:

3(a⁴ + b⁴ + c⁴ + s⁴) = (a² + b² + c² + s²)²

In this case, if we work in units of 1/8 miles, we have: a = 8, b = 5, c = 3, and writing x = s²:

3(8⁴ + 5⁴ + 3⁴ + x²) = (8² + 5² + 3² + x)²
14406 + 3x² = 9604 + 196x + x²
x² – 98x + 2401 = 0
(x – 49)² = 0
x = 49
s² = 49
s = 7

Solution: The distance between the churches in 7/8 miles. Here is a short program that uses the equation given above and the [[ `quadratic()` ]] function from enigma.py to solve the puzzle:

Run: [ @repl.it ]

```from enigma import quadratic, printf

# given a, b, c, calculate values for x
def solve(a, b, c, domain="F"):
(A, B, C) = (a * a, b * b, c * c)
T = A + B + C
# solve for x^2
for X in quadratic(2, -2 * T, 3 * (A * A + B * B + C * C) - T * T, domain=domain):
# solve for x
for x in quadratic(-1, 0, X, domain=domain):
yield x

# solve the puzzle
for x in solve(1, 0.625, 0.375):
if x > 0:
printf("churches are {x} miles apart")
```

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