# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1315: Going for gold

From New Scientist #2473, 13th November 2004

Messrs Archer and Bowman each fired three arrows. The arrows recorded six different scores between 2 and 10.

The cumulative score of each of them at any stage was always a prime number. Archer had the greater cumulative score after each had fired one arrow and again after each had fired three arrows, Bowman had the greater cumulative score after each had fired two arrows.

What did Bowman score with each of his arrows? Give the scores in the order in which they were recorded.

When I did archery I was told you couldn’t “fire” an arrow, as there was no fire involved. So, we used to “shoot” arrows.

[enigma1315]

### One response to “Enigma 1315: Going for gold”

1. Jim Randell 21 June 2014 at 7:34 am

This recursive Python program solves the problem in 37ms.

```from itertools import permutations
from enigma import irange, Primes, printf

# possible scores
scores = set(irange(2, 10))

# primes up to 30
primes = Primes(30)

def solve(A=[], B=[], cA=[0], cB=[0]):
# how many arrows have been shot
n = len(A)
if n == 1:
# check scores after the 1st arrow
if not(cA[1] > cB[1]): return
elif n == 2:
# check scores after the 2nd arrow
if not(cB[2] > cA[2]): return
elif n == 3:
# check scores after the 3rd (and final) arrow
if cA[3] > cB[3]:
# output a solution
printf("A = {A} => {cA} / B = {B} => {cB}", cA=cA[1:], cB=cB[1:])
return
# choose scores for A and B
for (a, b) in permutations(scores.difference(A + B), 2):
(ca, cb) = (cA[-1] + a, cB[-1] + b)
if ca in primes and cb in primes:
solve(A + [a], B + [b], cA + [ca], cB + [cb])

solve()
```

Solution: Bowman’s scores (in order) are 3 points, 10 points, 4 points.

Archer’s scores (in order) are 5 points, 6 points, 8 points.

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