Project Euler question 41:
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, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
I have the functions for checking primality, however, instead of going through all numbers up till 987654321, I decided to write a function which generates all the pandigital numbers through recursion.
def make_pan(curr): global pandigital_numbers if len(curr) < 9: for i in range(1, 10): if str(i) in curr: continue else: make_pan(curr + str(i)) else: pandigital_numbers.append(int(curr))
There is a list which holds all of the generated pandigital numbers (
pandigital_numbers). For some reason, my program is outputting that there is no prime pandigital number in the list. Is there something that my
make_pan function is doing to generate all the numbers?
P.S. The initial function call is
make_pan("") to start the recursive process