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
      for head in divisors(hb):
        if not(tail < head): continue
        belly = hb // head
        if not(head < belly): continue
        back = tail + head + belly
        r[back].append((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
        r2[back].append((tail, head, belly))
    
    # and this time back is unique
    for (back, vs) in r2.items():
      if len(vs) != 1: continue
      (tail, head, belly) = vs[0]
      printf("tail={tail} [head={head} belly={belly} back={back}]")
    

    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!

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: