Enigmatic Code

Programming Enigma Puzzles

Enigma 1294: Think of an animal

From New Scientist #2452, 19th June 2004 [link]

My young Australian nephew is getting good at arithmetic, and is gradually learning the names of a good number of animals. So I set him the following puzzle:

Think of a number, multiply it by 7, add 35, divide by 7, then take away the number you first thought of. Letting 1=A, 2=B, 3=C and so on, work out which letter your answer represents. Now think of an animal beginning with that letter.

In advance I had written “elephant” on a piece of card to amaze him. However, after thinking of a number he then performed the next four numerical steps in the wrong order, getting a positive whole number at each stage. He then worked out which letter his answer represented. However, he was unable to think of an animal beginning with that letter.

What number did he first think of, and what letter did he end up with?

Note: I am waiting for a phone line to be connected at my new house, so I only have sporadic access to the internet at the moment. The current estimate is that the line will be connected at the end of September 2014.


One response to “Enigma 1294: Think of an animal

  1. Jim Randell 12 September 2014 at 12:37 pm

    This Python program runs in 38ms.

    from itertools import permutations
    from enigma import irange, printf
    # the operations...
    # multiply by 7
    def op1(n, m):
      return n * 7
    # add 35
    def op2(n, m):
      return n + 35
    # divide by 7
    def op3(n, m):
      (n, r) = divmod(n, 7)
      if r > 0: raise ValueError()
      return n
    # take away the number you first thought of
    def op4(n, m):
      n -= m
      if n < 1: raise ValueError()
      return n
    # function composition
    def compose(n, m, fns):
      for fn in fns:
        n = fn(n, m)
      return n
    # choose an order for the operations
    for ops in permutations((op1, op2, op3, op4)):
      # ignore the correct order
      if ops == (op1, op2, op3, op4): continue
      # choose a number to start with
      for m in irange(1, 26):
        # perform the operations
          n = compose(m, m, ops)
        except ValueError:
        if not(0 < n < 27): continue
        letter = chr(64 + n)
        printf("{m} [{ops}] => {n} \"{letter}\"", ops=' '.join(x.__name__ for x in ops))

    Solution: He started with 14 and ended up with the letter “Q”.

    There are only three options:

    7 ⇒ “K”
    14 ⇒ “Q”
    21 ⇒ “W”

    These can be achieved by:

    × 7 → + 35 → – m → ÷ 7
    × 7 → – m → + 35 → ÷ 7

    Since the nephew is Australian we can assume that he knows of the Kangaroo/Koala/Kookaburra and Wombat/Wallaby, but perhaps not the Quokka/Quoll, leaving “Q” as the remaining option.

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: