Enigmatic Code

Programming Enigma Puzzles

Enigma 1560: Alphabetically

From New Scientist #2723, 29th August 2009 [link]

I have written down a list of some numbers (the smallest of which is odd) and then consistently replaced digits with letters throughout, with different letters used for different digits. In this way the list has become:

ALPHA
BETA
CHI
THETA
ALPHABETICALLY

All the numbers in the list are divisible by 9, and indeed ALPHABETICALLY and at least one other are divisible by 99.

Give the numerical value of ALPHABETICALLY.

[enigma1560]

Advertisements

3 responses to “Enigma 1560: Alphabetically

  1. jimrandell 22 February 2012 at 2:30 pm

    The following Python program runs in 292ms.

    from itertools import permutations
    from enigma import split, concat, printf
    
    d0 = set(range(10))
    
    # CHI is a 3-digit odd multiple of 9
    # consider 13*9 to 111*9 in steps of 2*9
    for CHI in range(117, 1008, 18):
      (C, H, I) = split(CHI, int)
      d1 = set((C, H, I))
      if len(d1) != 3: continue
    
      # BETA is a 4-digit multiple of 9
      # consider 112*9 to 1111*9 in steps of 9
      for BETA in range(1008, 10008, 9):
        (B, E, T, A) = split(BETA, int)
        if 0 in (B, T, A): continue
        d2 = d1.union((B, E, T, A))
        if len(d2) != 7: continue
    
        # THETA is a multiple of 9
        THETA = int(concat(T, H, E, T, A))
        if THETA % 9: continue
    
        # ALPHA is a 5-digit multiple of 9
        d3 = d0.difference(d2)
        for (L, P) in permutations(d3, 2):
          ALPHA = int(concat(A, L, P, H, A))
          if ALPHA % 9: continue
    
          # one of them must also be a multiple of 99
          if all(n % 99 for n in (ALPHA, BETA, CHI, THETA)): continue
    
          # ALPHABETICALLY is a multiple of 9 and 99
          Y = d3.difference((L, P)).pop()
          ALPHABETICALLY = int(concat(ALPHA, B, E, T, I, C, A, L, L, Y))
          if ALPHABETICALLY % 99 or ALPHABETICALLY % 9: continue
    
          printf("ALPHABETICALLY={ALPHABETICALLY} [ALPHA={ALPHA} BETA={BETA} CHI={CHI} THETA={THETA}]")
    

    Solution: ALPHABETICALLY = 81378406928115.

    ALPHA (81378) is also divisible by 99.

  2. Jim Randell 5 March 2017 at 10:19 pm

    This puzzle can be solved using the general alphametic solver (SubstitutedExpression()) from the enigma.py library.

    This run file executes in 97ms, so it’s faster than my program above.

    #!/usr/bin/env python -m enigma -r
    
    # solver to use
    SubstitutedExpression
    
    # the answer to the problem
    --answer="ALPHABETICALLY"
    
    # CHI is odd
    "CHI % 2 = 1"
    
    # all numbers on the list are divisible by 9
    "ALPHA % 9 = 0"
    "BETA % 9 = 0"
    "CHI % 9 = 0"
    "THETA % 9 = 0"
    "ALPHABETICALLY % 9 = 0"
    
    # ALPHABETICALLY is divisible by 99
    "ALPHABETICALLY % 99 = 0"
    
    # and so is (at least) one of the other numbers
    "not all(x % 99 != 0 for x in (ALPHA, BETA, CHI, THETA))"
    
  3. Brian Gladman 8 April 2017 at 10:53 pm
    from itertools import permutations, product
    from functools import reduce
    
    compose = lambda seq: reduce(lambda x, y: 10 * x + y, seq)
    
    # Choose digits for H and I (I odd)
    for H, I in product(range(10), (1, 3, 5, 7, 9)):
      
      # CHI is a multiple of 9, so C = -(H + I) mod 9
      C = (8 * (H + I)) % 9
      C = C if C else 9
      s7 = set(range(10)).difference([C, H, I])
      if len(s7) != 7:
        continue
      
      # now choose digits for A and E
      for A, E in permutations(s7, 2):
        
        # THETA is a multiple of 9, so 2.T = -(A + E + H) mod 9
        T = (4 * (A + E + H)) % 9
        T = T if T else 9
        s4 = s7.difference([A, E, T])
        if len(s4) != 4:
          continue
        
        # BETA is a multiple of 9, so B = -(A + E + T) mod 9
        B = (8 * (A + E + T)) % 9
        B = B if B else 9
        s3 = s4.difference([B])
        if len(s3) != 3:
          continue
        
        # assign the remaining digits to the remaaining letters
        for L, P, Y in permutations(s3):      
          # form ALPHA and ALPHABETICALLY
          alpha = compose([A, L, P, H, A])
          abet = compose([A, L, P, H, A, B, E, T, I, C, A, L, L, Y])
      
          # check that they are multiples of 9
          if alpha % 9 == 0 and abet % 9 == 0:         
            # form the numbers CHI, BETA and THETA
            chi = compose([C, H, I])
            beta = compose([B, E, T, A])
            theta = compose([T, H, E, T, A])
            
            # at least one of ALPHA, BETA, CHI and THETA is divisible by 11   
            if [x for x in (alpha, beta, chi, theta) if not x % 11]:
              print(f'ALPHABETICALLY {abet:,d} (ALPHA = {alpha}, BETA = {beta}'
                    f', CHI = {chi}, THETA = {theta}).')
    

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: