# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1409: On target

From New Scientist #2569, 16th September 2006

At the initial stage the soldiers Ike, Jay and Kay were at three different points equidistant from their target. At that stage Ike was 4 kilometres from Jay and also 4 kilometres from Kay. Then Jay inched forward towards the target but stopped short at another point also 4 kilometres from Ike. At this second stage the distances between any two of Ike, Jay, Kay and the target were all whole numbers of kilometres.

At the second stage how far apart were Jay and Kay?

[enigma1409]

### 2 responses to “Enigma 1409: On target”

1. Jim Randell 27 July 2013 at 7:54 am

I originally solved this when it was published in the magazine using Perl that uses code to check two possible cases (determined by analysis). Here’s a similar approach in Python, it runs in 52ms.

```# considering the sine rule on TIJ/TIK:
# 4 / sin(2 phi) = t / sin(90 - phi) = t / cos(phi)
# and on JIJ':
# a / sin(phi) = 4 / sin(90 - phi) = 4 / cos(phi)
# together these give us:
# 2 sin(phi) = 4 / t = a / 4
# hence: a t = 16
# (the same result follows from considering them as similar triangles)
# and as both a and t are integral values it follows they are
# factors of 16, and as J does not reach the target it
# follows that a < t
# so: (a, t) = (1, 16) or (2, 8)

from fractions import Fraction as F
from enigma import divisor_pairs, is_square, printf

for (a, t) in divisor_pairs(16):
if not(a < t): break

# sin^2 phi, cos^2 phi, cos 4phi
s2 = F(4, t ** 2)
c2 = 1 - s2
c4 = s2 ** 2 + c2 ** 2 - 6 * s2 * c2

# compute x by the cosine rule
b = t - a
x2 = t ** 2 + b ** 2 - 2 * t * b * c4
x = is_square(x2)
printf("x={x} [x2={x2} t={t} a={a} s2={s2} c4={c4}]")
```

Solution: Jay and Kay were 7km apart.

• Jim Randell 27 July 2013 at 8:08 am

This diagram shows where the derivation of the equations used in the program.

By considering the similar triangles JIJ’ and ITJ (or ITK) it follows that:

a : 4 = 4 : t
⇒ a.t = 16

Hence a and t are integer factors of 16 and a < t, so: (a, t) is (1, 16) or (2, 8).

And we can eliminate one of these possibilities to give a unique solution by further analysis.

Considering the quadrilateral IJ’TK we see that:

∠IJ’T + ∠IKT = (90° + φ) + (90° – φ) = 180°

∠KIJ’ + ∠KTJ’ = (90° – φ + 90° – 3φ) + (2φ + 2φ) = 180°

Hence IJ’TK is a cyclic quadrilateral, so by applying Ptolomy’s Theorem to it we get:

IT.J’K = IJ’.KT + IK.J’T

so:

t.x = 4t + 4(t – a) = 8t – 4a
x = 8 – 4a/t

But x is an integer so t divides 4a, leaving (a, t) = (2, 8) as the only possible solution.

Hence x = 7.