Problem 38

completed December 12, 2011

Comments

I really only needed to test numbers starting with 9. But it ended up just being easier for me to test all numbers. The answer came pretty quickly.

Code

def str2num(n):
	return ''.join(map(str, n))		

#create a concatenation and break if it cannot be 9 digits exactly
from math import log10
def concatenate(n):
	num = (n)
	mult = 2
	while (log10(float(num)) < 8):
		num = str2num((num, mult * n))
		mult += 1
	return num
	
#determine if a number is 9-digit pandigital
def pandigital(n):
	num = str(n)
	for i in range(1, 10):
		if num.count(str(i)) != 1: return 'FALSE'
	if (num.count(str(0)) > 0): return 'FALSE'
	else: return 'TRUE'


mylist = []
for x in range(1, 10**7):
	concax = concatenate(x)
	if pandigital(concax) == 'TRUE':
		mylist.append(concax)
	print x
		
print max(mylist)