Lexicographic Enumeration

Screen Shot 2014-12-23 at 1.12.04 AM

I recently implemented Dijkstra’s algorithm, published in 1976, for lexicographically enumerating permutations in Python for Project Euler’s problem 32:

“Pandigital products
Problem 32
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.

The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand / multiplier / product identity can be written as a 1 through 9 pandigital.”

Here is the Python code that implements Dijkstra’s algorithm for enumerating the pandigital numbers:

Given this code we can then check which numbers are unusual, as defined above.

By the way, friend me on Project Euler if you are also a fan of this site.

My friend code is: 704085_afc937d56367db90098e60535d34393a


Leave a Reply

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s