def findlargestpandigital(): for n in range(9, 1, -1): pan = makepandigital(n, True) for p in pan: pint = array2int(p) # print "Testing: " + repr(pint) if isprime(pint): print "Found the largest pandigital prime: " + repr(pint) return pint
else: if len(num) == maxlen: rval = int(num) return rval # Takes in a pandigital number and determines if it can # be formed by concatenating the product of an integer # We do this by taking the first n digits, and multiplying # them by the sequence (1,2,3,4,...) until we have a # 9 digit number, then we can compare that def findpancat(pan): rval = 0 ipan = array2int(pan) # We only need to search for something < 5 digits for ii in range(1, 6): start = array2int(pan[0:ii]) cprod = makecatprod(start, 9) if cprod == ipan: rval = 1 return rval if __name__ == "__main__": plist = makepandigital(9, True) for pan in plist: findpancat(pan) if findpancat(pan): print ("The largest pandigital that can be formed " + "as a concatenated product is: %d" % (array2int(pan))) break
def substrdiv(string): subdiv = 1 # Make the prime array list pl = [0, 1, 2, 3, 5, 7, 11, 13, 17] for si in range(2, 9): substr = string[si-1:si+2] div = pl[si] # print ("subgroup: " + substr + " % " + # repr(div) + " = " + repr((int(substr)%div))) if (int(substr) % div != 0): subdiv = 0 break return subdiv if __name__ == "__main__": pandigital09 = makepandigital(9, False, 0) total = 0 for num in pandigital09: # Make it into a string s09 = ''.join(str(x) for x in num) # make sure we don't have a leading zero if s09 != str(int(s09)): continue # Check the sub-string divisibliilty if substrdiv(s09): total += int(s09) print ("The total of 0-9 pandigital numbers with this property is: " + repr(total))