Enigmatic Code

Programming Enigma Puzzles

Enigma 1579: Fifteen

From New Scientist #2744, 23rd January 2010 [link]

In the addition sum above the digits have been replaced by letters and smiley faces. Different letters stand for different digits, the same letter stands for the same digit, a smiley face can be any digit, and leading digits cannot be zero.

If FIVE is divisible by 5 and ELEVEN is divisible by 11, what number is FIFTEEN?

[enigma1579]

Advertisements

One response to “Enigma 1579: Fifteen

  1. jimrandell 7 February 2012 at 8:19 pm

    The following Python program runs in 45ms.

    from itertools import permutations
    from enigma import concat
    
    # FIVE is divisible by 5 (hence E is 0 or 5).
    # ELEVEN is divisible by 11 (and can't have a leading 0).
    # Hence E = 5.
    
    E = 5
    
    # consider the FI+IV+VE = TE part of the sum (10^3 10^2)
    # the carry coming in is c2 = 0, 1 or 2
    d1 = set(range(10)).difference((E,))
    for (F, I, V) in permutations(d1, 3):
      if F < 2: continue
    
      TE = 10 * (F + I + V) + (I + V + E)
      (d, r) = divmod(TE, 10)
      c2 = 5 - r
      if not c2 in (0, 1, 2): continue
      (c4, T) = divmod(d, 10)
    
      d2 = d1.difference((F, I, V, T))
      for L in d2:
    
        ELEVE0 = int(concat(E, L, E, V, E)) * 10
        N = 11 - (ELEVE0 % 11)
    
        d3 = d2.difference((N,))
        if len(d3) != 4: continue
    
        # consider the V + E + ? = E column (10^1)
        for c1 in (0, 1, 2, 3):
          if not(0 <= 10*c2 - (V + c1) < 10): continue
    
          # consider the ? + E + ? + ? column (10^0)
          if not(0 <= 10*c1 + N - E < 28): continue
    
          # consider the ? + F + I = F column (10^4)
          for c5 in (0, 1, 2):
            if not(0 <= 10*c5 - (I + c4) < 10): continue
    
            # consider the ? + ? + F = I column (10^5)
            for c6 in (0, 1, 2):
              if not(0 <= (10*c6 + I) - (F + c5) < 19): continue
    
              # consider the ? + ? + ? = F column (10^6)
              if not(2 < F - c6 < 10): continue
    
              print("FIFTEEN={FIFTEEN} FIVE={FIVE} ELEVEN={ELEVEN}".format(FIFTEEN=concat(F, I, F, T, E, E, N), FIVE=concat(F, I, V, E), ELEVEN=ELEVE0+N))
    

    Solution: FIFTEEN = 4043551.

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: