Enigmatic Code

Programming Enigma Puzzles

Enigma 1103: Brush strokes

From New Scientist #2259, 7th October 2000

Our sign painter has an odd way of calculating his charges. For each continuous brush-stroke (which can be any shape but must not go over the same ground twice) he charges £1. He paints capital letters in a simple style and does not use two strokes where one would do. So, for example his U, E, G and H would cost £1, £2, £2 and £3 respectively.

My house number is a three-figure prime and I have asked the sign painter to spell out the three different digits (so that, for example, 103 would be ONE NOUGHT THREE and would cost £24). For my house number the cost in pounds equals the sum of the three digits and is also a prime.

What is my [house] number?



One response to “Enigma 1103: Brush strokes

  1. Jim Randell 7 August 2017 at 7:34 am

    This Python program runs in 44ms.

    from enigma import Primes, nsplit, printf
    primes = Primes(1000)
    # digits to words
    words = [
    # cost of letters (number of strokes)
    # Q could be 1 or 2, but doesn't occur
    cost = {
      'A': 2, 'B': 1, 'C': 1, 'D': 1, 'E': 2, 'F': 2, 'G': 2,
      'H': 3, 'I': 1, 'J': 2, 'K': 2, 'L': 1, 'M': 1, 'N': 1,
      'O': 1, 'P': 1, 'Q': 2, 'R': 1, 'S': 1, 'T': 2, 'U': 1,
      'V': 1, 'W': 1, 'X': 2, 'Y': 2, 'Z': 1,
    # consider 3 digit primes
    for p in primes.range(100, 999):
      # the three digits are all different
      ds = nsplit(p)
      if len(set(ds)) != len(ds): continue
      # the sum of the individual digits should also be prime
      s = sum(ds)
      if s not in primes: continue
      # the cost of the individual letters should be the same
      k = sum(sum(cost[x] for x in words[d]) for d in ds)
      if k != s: continue
      printf("p={p} s={s}")

    Solution: Your house number is 829 (EIGHT TWO NINE).

    229 is another 3 digit number that meets all the conditions, except that the digits all be different.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: