# 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: Find the divisor and all the digits of the sum.

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

[enigma9]

### 3 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:
#
#  div x r = bp
#  bd - bp = p  =>  d - p = p  => d = 2p
#  div x y = xr
#  pa - xr = yx
#  div x p = yrd
#  yxy - yrd = x  => xy - rd = x
#  xp - xr = r  => p - r = r => p = 2r
#  div x qz = rdd
#  rzb - rdd = d  => zb - dd = d

from itertools import permutations
from enigma import printf

d1 = set(range(10))
# from  & : 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):
# 
(z, z1) = divmod(12 * d - b, 10)
if z1 > 0: continue

d3 = d2.difference((b, x, z))
if len(d2) - len(d3) != 3: continue

# 
(div, div1) = divmod(10 * b + p, r)
if div1 > 0: continue

# 
(y, y1) = divmod(10 * x + r, div)
if y1 > 0: continue

# 
a = 10 * (y - p) + 11 * x + r

# 
(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  & 
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.

• Jim Randell 1 February 2018 at 4:22 pm

Or, as a run file:

```#!/usr/bin/env python -m enigma -r

SubstitutedDivision

"bdaypzb / ?? = rypyqz"

"bd - bp = p"
"pa - xr = yx"
"yxy - yrd = x"
"xp - xr = r"
""
"rzb - rdd = d"
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.