Random Post
Recent Posts
Recent Comments
Archives
Categories
- article (11)
- enigma (1,609)
- enigma-book-1982 (70)
- misc (5)
- project euler (2)
- puzzle (90)
- puzzle# (173)
- site news (76)
- tantalizer (189)
- teaser (7)
- today (1)
Site Stats
- 310,314 hits
Programming Enigma Puzzles
From New Scientist #1732, 1st September 1990 [link]
In the two division sums below, the six-figure dividend is the same but the divisor and the answer have been interchanged (that is, the first is x ÷ y = z and the second is x ÷ z = y). No digit occurs in both the divisor and the answer, and no digit in the dividend is used in either the divisor or the answer.
What is the dividend?
[enigma579]
We can express both division sums (and the additional constraints) as alphametic expressions (using additional symbols for the “blanks”), and then use the [[
SubstitutedExpression
]] solver from the enigma.py library to solve them.(The [[
SubstitutedDivision
]] solver automates this process for a single division sum, but for multiple sums with extra conditions it is easier just to use the [[SubstitutedExpression
solver).The following run file executes in 306ms.
Run: [ @repl.it ]
Solution: The dividend is: 109116.
The two division sums are: 109116 ÷ 252 = 433, and: 109116 ÷ 433 = 252.
The first division sum produced 14 possible solutions, which were narrowed by the second division sum to a single solution. A quite verbose solution, but it gets the right answer and I have included the full divisions sums at the end of the solution.
Re-using some of my earlier code, I found a much shorter solution.
I tried the free Wing Personal IDE to format my code to PEP8 – it has a Source/Reformatting option in the Main Menu to format the code to PEP8. The biggest change to my normal practice was putting the ‘continue’ statment on a separate line.
@Frits:
In both of my solutions I used a range for checking the six digit dividend from 100,000 to 999,999,
as this seemed appropriate programmatically. I notice your programme used a range of 100,000 to 200,000. Did you find a reason to use this lower upper bound value?
@GeoffR, the reason is mentioned line above (A has to be 1, see 2nd division). I added it to bring the run time under 1 second.