# Enigmatic Code

Programming Enigma Puzzles

## Enigma 331: All change please

From New Scientist #1479, 24th October 1985 [link]

In the following long division sum the figures given have this is common — they are all wrong. The sum comes out exactly.

Write out the correct long division sum.

[enigma331]

### One response to “Enigma 331: All change please”

1. Jim Randell 5 February 2016 at 7:53 am

This Python program uses the SubstitutedDivision() solver from the enigma.py library to find division sums with the right “shape”, and then checks them to see if all the digits giving in the diagram are wrong. It runs in 979ms.

```from enigma import SubstitutedDivision

# check specified digits are wrong
def check(n, s):
return all(b == '?' or b != a for (a, b) in zip(str(n), s))

# look for solutions with the right shape
p = SubstitutedDivision(
'?????', '??', '????',
[('??', '??', '??'), ('???', '???', '??'), ('???', '???', '?'), ('??', '??', '')]
)

for s in p.solve():
# check given digits are wrong
if not check(s.a, '????8'): continue
if not check(s.b, '41'): continue
if not check(s.c, '???1'): continue
i = p.solution_intermediates(s)
if not(check(i[0][1], '?5') and check(i[0][2], '2?')): continue
if not(check(i[1][1], '1?8') and check(i[1][2], '3?')): continue
if not(check(i[2][1], '118') and check(i[2][2], '9')): continue
if not(check(i[3][0], '96') and check(i[3][1], '?4')): continue

p.output_solution(s)
```

Solution: The correct sum is 70992 ÷ 36 = 1972.