Enigmatic Code

Programming Enigma Puzzles

Enigma 9: Bungled division

From New Scientist #1151, 19th April 1979 [link]

Uncle Bungle has been doing a division sum with letters substituted for digits. Was it by accident or design, I wonder, that he left out the divisor?

What was left looked like this:

Enigma 83

Find the divisor and all the digits of the sum.

This puzzle was subsequently re-published verbatim as Enigma 83.

[enigma9]

Advertisements

2 responses to “Enigma 9: Bungled division

  1. Jim Randell 6 December 2011 at 11:09 pm

    The following Python code runs in 29ms.

    # so we have the following:
    #
    # [1] div x r = bp
    # [2] bd - bp = p  =>  d - p = p  => d = 2p
    # [3] div x y = xr
    # [4] pa - xr = yx
    # [5] div x p = yrd
    # [6] yxy - yrd = x  => xy - rd = x
    # [7] xp - xr = r  => p - r = r => p = 2r
    # [8] div x qz = rdd
    # [9] rzb - rdd = d  => zb - dd = d
    
    from itertools import permutations
    from enigma import printf
    
    d1 = set(range(10))
    # from [2] & [7]: r,p,d = 1,2,4 or 2,4,8
    for (r, p, d) in ((1, 2, 4), (2, 4, 8)):
      d2 = d1.difference((d, p, r))
      for (b, x) in permutations(d1, 2):
        # [9]
        (z, z1) = divmod(12 * d - b, 10)
        if z1 > 0: continue
    
        d3 = d2.difference((b, x, z))
        if len(d2) - len(d3) != 3: continue
    
        # [1]
        (div, div1) = divmod(10 * b + p, r)
        if div1 > 0: continue
    
        # [3]
        (y, y1) = divmod(10 * x + r, div)
        if y1 > 0: continue
    
        # [4]
        a = 10 * (y - p) + 11 * x + r
    
        # [8]
        (q, q1) = divmod(100 * r + 11 * d, div)
        if q1 > 0: continue
        (q, q1) = divmod(q - z, 10)
        if q1 > 0: continue
    
        d4 = d3.difference((a, q))
        if len(d3) - len(d4) != 2: continue
    
        # check remaining equations [5] & [6]
        if div * p != 100 * y + 10 * r + d: continue
        if 10 * (x - r) + y - d != x: continue
    
        printf("{b}{d}{a}{y}{p}{z}{b} / {div} = {r}{y}{p}{y}{q}{z} rem {d}")
    

    Solution: The divisor is 32. The sum is 6851496 / 32 = 214109 remainder 8.

    • Jim Randell 13 July 2014 at 8:08 am

      Using the SubstitutedDivision() solver I wrote for Enigma 206 this puzzle can be solved with the following program in 52ms.

      from enigma import SubstitutedDivision
      
      # the dividend has 7 digits and the result has 6 digits
      # therefore the divisor is in the range:
      #   [ 1234561 / 1000000, 9876549 / 100000 ] = [ 2, 98 ]
      # so the divisor has one or two digits
      #
      # but some of the multiples in the intermediate sums have
      # three digits hence the divisor cannot have only one digit
      
      SubstitutedDivision(
        'bdaypzb', '??', 'rypyqz',
        [('bd', 'bp', 'p'), ('pa', 'xr', 'yx'), ('yxy', 'yrd', 'x'), ('xp', 'xr', 'r'), None, ('rzb', 'rdd', 'd')]
      ).go()
      

      Of course, the same program works for Enigma 83.

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: