### Random Post

### Recent Posts

- Enigma 1065: Cute cubes
- Enigma 444: Rows and rows
- Puzzle 50: Football and addition
- Enigma 1066: Members of the clubs
- Enigma 443: The bells they are a-changing
- Tantalizer 455: Ballistico
- Tantalizer 456: Square deal
- Enigma 1067: Bye!
- Enigma 442b: Oh yes I did! Oh no you didn’t!
- Puzzle 51: A multiplication

### Recent Comments

Brian Gladman on Enigma 1065: Cute cubes | |

Jim Randell on Enigma 1065: Cute cubes | |

geoffrounce on Enigma 444: Rows and rows | |

Jim Randell on Enigma 444: Rows and rows | |

geoffrounce on Enigma 1611: Three sister… |

### Archives

### Categories

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

### Site Stats

- 180,599 hits

Advertisements

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!