# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1269: It was a dark and …

From New Scientist #2425, 13th December 2003 [link]

It was a dark and stormy night when the disciples took Jesus for a birthday boat trip on Galilee. He set them a puzzle, which went as follows.

“It was a dark and stormy night when Caiaphas set the priests a puzzles, which went as follows:

“It was a dark and stormy night when Pilate set the guards a puzzle, which went as follows:

“I want you to tell me how many camels are in Caesar’s stable. I will tell you the sum of all the positive integers which divide exactly into the answer.”

“He told them and they worked out the answer. Now I, Caiaphas, want you to tell me how many camels are in the stable. I will tell you the result of multiplying the answer minus 10 by the answer.”

He told them and they worked out the answer. Now I, Jesus, want you to tell me how many camels are in the stable. I will tell you the remainder when the answer is divided by 8.”

He told them and they worked out the answer. Now everyone knows that the number of camels is at least 1 and no more than 13.

How many camels are in the stable?

[enigma1269]

### 7 responses to “Enigma 1269: It was a dark and …”

1. Jim Randell 21 December 2014 at 10:34 am

This Python program runs in 30ms.

```from collections import defaultdict
from enigma import irange, divisors, printf

# find inputs from <ns> that have a unique measure <m>
def unique(ns, m):
r = defaultdict(list)
for n in ns:
r[m(n)].append(n)
for vs in r.values():
if len(vs) == 1:
yield vs[0]

# measures for each of the puzzles
mp = lambda n: sum(divisors(n))
mc = lambda n: (n - 10) * n
mj = lambda n: n % 8

# find unique solutions for each puzzle
ns = irange(1, 13)
for m in (mp, mc, mj):
ns = sorted(unique(ns, m))
printf("ns = {ns}")
```

Solution: There are 10 camels in the stable.

• geoffrounce 21 December 2014 at 12:44 pm
```from collections import defaultdict
cdict = defaultdict(list)

for camels in range(1,14):
for num in range(1,14):
if camels % num == 0:
cdict[camels] += [num]  # reference divisors to number of camels

for c in cdict:
if sum(cdict[c]) > 10:  # Caiaphas' requirement
sv = sum(cdict[c])  # sum of divisors for each number of camels
if (sv - 10) % 8 == 0:   # number of camels must be an integer
print('No of camels in stable is',c)

```
2. Hugh Casement 21 December 2014 at 4:51 pm

The name is Caiaphas. See, for example, Matthew 26.

• Jim Randell 21 December 2014 at 6:41 pm

Thanks. I’ve fixed it up now.

• Hugh Casement 22 December 2014 at 12:21 pm

I can’t see that there’s a unique solution. The remainder on dividing by 8 is the same for 2 and 10 (as also for 1 and 9, 3 and 11, 4 and 12, 5 and 13). All numbers below 10 have been excluded by the n(n – 10) test, so there’s nothing left!

• Jim Randell 22 December 2014 at 6:38 pm

I think it works out this way…

We first consider Pilate’s puzzle. He told the guards the sum of the divisors of n (where n is the number of camels), and they worked out the answer. We don’t know the number he told the guards, but we can eliminate the possibility of there being 6 or 11 camels (as the divisors of these numbers both sum to 12).

Then we consider Caiaphas’ puzzle. He told the priests the value of n × (n – 10), and they worked out the answer. But they also know that Pilates’ guards worked out the answer, so n can’t be 6 or 11. From the remaining possibilities we can eliminate 1 and 9, 2 and 8, 3 and 7 (each pair has the same value). So that only leaves 4, 5, 10, 12 and 13 as possibilities.

Finally we consider Jesus’ puzzle. He told the disciples the remainder modulo 8, and they worked out the answer. They also know by now that n can only be 4, 5, 10, 12 or 13.

So, we can eliminate 4 and 12 (n mod 8 = 4), and 5 and 13 (n mod 8 = 5), leaving 10 as the only remaining candidate (n mod 8 = 2).

So it follows that Pilate told his guards the sum of the divisors was 18, so they can deduce that n = 10. Caiaphas told his priests that n × (n – 10) = 0, from which they would immediately be able to deduce that n = 10 (without even needing to know anything about Pilate’s puzzle – which is a bit disappointing). Jesus told his disciples that n mod 8 = 2, so they do need to know about Caiaphas’ puzzle (in order to eliminate n = 2), but not about Pilate’s puzzle.

We need to know about all three puzzles to deduce the answer.

• Hugh Casement 23 December 2014 at 10:28 am

Thanks for the explanation, Jim. I agree it’s a somewhat unsatisfactory puzzle (and some people might find it offensive).