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.

Enigma 331

Write out the correct long division sum.

[enigma331]

Advertisements

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.

    Enigma 331 - Solution

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: