### Random Post

### Recent Posts

- Enigma 1105: Road ants
- Enigma 406: The ritual
- Puzzle 69: Division: letters for digits
- Enigma 1106: Not a square unused
- Enigma 405: Uncle bungles the answer
- Enigma 401: Uncle bungles the answer
- Puzzle 70: Football five teams: new method
- Enigma 1107: Factory work
- Enigma 404: Regular timepiece
- Tantalizer 477: Precognition

### Recent Comments

Jim Randell on Enigma 1105: Road ants | |

geoffrounce on Enigma 35: Digits all wro… | |

hakank on Puzzle 70: Football five teams… | |

saracogluahmet on Enigma 1740: Sudoprime | |

Jim Randell on Enigma 406: The ritual |

### Archives

### Categories

- article (11)
- enigma (1,089)
- misc (2)
- project euler (2)
- puzzle (23)
- site news (42)
- tantalizer (23)
- teaser (3)

### Site Stats

- 159,398 hits

This is another problem that can be fed directly into the

SubstitutedSum()solver from theenigma.pylibrary.This Python program runs in 52ms.

Solution:1912803 + 2428850 + 4312835 = 8654488.Instead of writing individual programs for such problems, I have added code to the

enigma.pylibrary that allows you call theSubstitutedSum()solver directly from the command line. This kind of problem can now be solved directly by just passing the parameters as command line arguments:Here is a MiniZinc solution;

Easier to programme as a Python permutation solution, but not as fast as MiniZinc

Hi so I had a go at the problem (sorry I’m quite new to python lol!!) and I made this

but it seems to be running a bit slowly can anyone help me??? Thanks again for the help!!

Hi Liam – Welcome to Enigmatic Code.

Your program produces the right answer, and on my machine it runs in about 1.2s (using PyPy 4.0.1, or about 19.4s using the standard Python 2.7.11 interpreter). The reason it’s slow is the simplicity of the algorithm. The nested

forloops construct all possible assignments of the digits to the letters, so the test at line 18 is evaluated 3,628,800 times (=factorial(10)).Three years ago, after coding up a solution to

Enigma 63– a similar problem – (using Python’sitertools.permutations()to generate all possible assignments of letters to digits), I decided to write a generic solver for such puzzles to save me the bother of having to write a custom program each time. (Puzzles like this were quite popular in early Enigmas). I ended up with a more sophisticated algorithm that does many fewer tests, and I’ve incorporated that into theSubstitutedSum()solver in theenigma.pylibrary. On this problem it runs about 1000× faster than your program (using the standard Python interpreter).Oh gosh I feel a bit slow now – who knew we we’re supposed to build fast programs and not just simple programmes! gosh 1000 x faster I see I have a lot of learning to do! I’m quite new to all this python stuff, sorry haha. Although I suppose if you’ve already written a computer to solve all these sorts of problems there’s not much point me writing one!! I’ll have a go at some of the other problems here then, thanks again for the help!

I love your code. For me it symbolises a lot of my feelings about programming as an art form: a perfect merging of mechanical beauty and gritty complexity. Sure, it’s not concise, but it exaggerates and elucidates the actual physicality of what is required to calculate a solution. Bravissimo.

Haha gosh that’s so nice of you fisty frodo (or should I call you fisty?) theres clearly a fierce debate here lol! You used some difficult words, but I think I know what you meant! Bravissimo is Spanish right? Yeah so maybe it’s time for programmers to write computers that are not fast but sort of more simple and I’m sure people would appreciate that! Thanks again!