Enigmatic Code

Programming Enigma Puzzles

Enigma 1164: Triple count

From New Scientist #2320, 8th December 2001 [link]

I call the number 25 “straight” because when written in words with capital letters it uses only straight lines. In fact, when written in simple capitals, it uses 29 line segments (including the hyphen), 11 of which are horizontal; also it has 10 letters. On the other hand 18 is not straight because it uses a curved G.

I have now written down three straight numbers in words with simple capitals. The first of the numbers is within 1 of the total number of line segments in the three numbers. The second on the numbers is within 1 of the total number of horizontal line segments in the three numbers. And the third of the numbers is within 1 of the total number of letters in the three numbers.

What are the three numbers?

[enigma1164]

Advertisements

One response to “Enigma 1164: Triple count

  1. Jim Randell 6 June 2016 at 8:39 am

    The answer on this one depends on how you write the letter Y. For the vast majority of the fonts on my system it consists of 3 line segments, but there are a few fonts (particularly “handwriting” fonts) that only use 2 line segments. But as the example given in the puzzle text (25 = TWENTY-FIVE) has 29 line segments using the 3 line segment version of Y, and only 28 if using the 2 line segment version, my program uses the 3 line segment version.

    This Python program runs in 41ms.

    from itertools import product
    from enigma import irange, int2words, printf
    
    # "straight letters" (when written in capitals)
    # record (number of line segments, number of horizontal line segments)
    straight = {
      ' ': (0, 0),
      '-': (1, 1),
      'a': (3, 1),
      'e': (4, 3),
      'f': (3, 2),
      'h': (3, 1),
      'i': (1, 0),
      'k': (3, 0),
      'l': (2, 1),
      'm': (4, 0),
      'n': (3, 0),
      't': (2, 1),
      'v': (2, 0),
      'w': (4, 0),
      'x': (2, 0),
      'y': (3, 0), # or (2, 0)
      'z': (3, 2),
    }
    
    # count the number of line segments
    def lines(s, i=0):
      try:
        return sum(straight[x][i] for x in s)
      except KeyError:
        return None
    
    # find "straight" numbers
    # (the following can never be straight: "hundred", "thousand", "*illion")
    d = dict()
    for j in irange(1, 99):
      s = int2words(j, hyphen='-')
      t = lines(s)
      if t is not None:
        h = lines(s, 1)
        n = sum(x.isalpha() for x in s)
        printf("[straight: {j} -> {s} ({t} segments, {h} horizontal, {n} letters)]")
        # record: number -> (line segments, horizontal line segments, letters)
        d[j] = (t, h, n)
    
    # choose three numbers
    for js in product(d.keys(), repeat=3):
      # group the numbers from the dictionary together
      groups = zip(*(d[j] for j in js))
      # and sum them
      sums = map(sum, groups)
      # and check the sums are within one of the chosen numbers
      if all(abs(x - y) < 2 for (x, y) in zip(js, sums)):
        printf("numbers = {js}")
    

    Solution: The three numbers are: 59, 20, 20.

    If the 2 line segment version of Y is used the solution is: 55, 20, 20.

    If you like complex expressions and shorter programs you can coalesce lines 49-53 into a single expression.

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: