I recently implemented Dijkstra’s algorithm, published in 1976, for lexicographically enumerating permutations in Python for Project Euler’s 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