# Enigmatic Code

Programming Enigma Puzzles

## Enigma 160: Fido’s fleas

From New Scientist #1305, 13th May 1982 [link]

Fido has fleas. He has fleas on his tail, a greater number on his head and yet a greater number on his belly. If you multiply those three numbers together, you get an amazing 3150. Why do that? Why indeed! So add them together instead and that will give you the number of fleas on his back.

Can you now work out the number of fleas on his tail? No, you cannot. Nor could you do it, even if you knew the number of fleas on his back. But, if I then threw in the fact that he has more on his belly than on head and tail put together, you could.

So how many fleas does Fido have on his tail?

[enigma160]

### 3 responses to “Enigma 160: Fido’s fleas”

1. Jim Randell 10 January 2014 at 7:49 am

A fairly straightforward puzzle. This Python program runs in 33ms.

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

# record (tail, head, belly) by their sum (= back)
r = defaultdict(list)
r2 = defaultdict(list)

# tail < head < belly, multiplied together they make 3150
for tail in divisors(3150):
hb = 3150 // tail
back = tail + head + belly

# but back must be ambiguous
for (back, vs) in r.items():
if len(vs) < 2: continue
# but head + tail < belly
for (tail, head, belly) in vs:
if not(head + tail < belly): continue

# and this time back is unique
for (back, vs) in r2.items():
if len(vs) != 1: continue
```

Solution: Fido has 7 fleas on his tail.

2. Brian Gladman 10 January 2014 at 9:56 am

Hi Jim,

I did this one but it is not worth publishing since it is essentially the same as yours. But your ‘answer’ of 33 had me worried since I got 7! But so does your code so I am not sure where the 33 comes from!

• Jim Randell 10 January 2014 at 10:02 am

Sorry. The solution really should be 7 (and that is what the code outputs). I’ve corrected it now in my first comment. Thanks for letting me know!

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