def pandigital_concatenated_multiples(): result_list = [] # 4-digit + 5-digit = 9-digit for n in range(9876, 5123, -1): str_sum = str(n) + str(n*2) if common.is_pandigital(str_sum, '123456789'): result_list.append((int(str_sum), int(n), int(n*2))) break # return just the largest 4-digit set # 3-digit + 3-digit + 3-digit = 9-digit for n in range(329, 123, -1): str_sum = str(n) + str(n*2) + str(n*3) if common.is_pandigital(str_sum, '123456789'): result_list.append((int(str_sum), int(n), int(n*2), int(n*3))) break # return just the largest 3-digit set # 1-digit + 2-digit + 2-digit + 2-digit + 2-digit = 9-digit for n in range(9, 5, -1): str_sum = str(n) + str(n*2) + str(n*3) + str(n*4) + str(n*5) if common.is_pandigital(str_sum, '123456789'): result_list.append((int(str_sum), int(n), int(n*2), int(n*3), int(n*4), int(n*5))) break # return just the largest 1-digit set return result_list
def test_is_pandigital_invalid(): """Tests the is_pandigital function with invalid numbers""" #: testing for numbers outside of the 9-10 digits range assert is_pandigital(123, True) is False assert is_pandigital(123, False) is False assert is_pandigital(123456789010, False) is False #: testing for zero assert is_pandigital(0, True) is False #: testing for repreating digits assert is_pandigital(1234567899, True) is False
def solve(): products = set() for p in xrange(10000): for x in xrange(2, int(p**0.5)): if p % x == 0 and is_pandigital('{}{}{}'.format(p, x, p / x)): products.add(p) return sum(products)
def max_pandigital_multiple(n): result = 0 p = int(9 / n) for i in range(10 ** (p - 1), 10 ** p): s = ''.join(str(i * j) for j in range(1, n + 1)) if len(s) > 9: break if is_pandigital(s, 9) and int(s) > result: result = int(s) return result
def solve(): result = [] for x in xrange(1, 100000): s = '' for y in xrange(1, 11): s += str(x * y) if y > 1 and is_pandigital(s): result.append(int(s)) return max(result)
def problem(): """ Attempt to solve the problem... """ print 'problem #41' max_p = 0 for prime in primes: if is_pandigital(prime): if prime > max_p: max_p = prime print 'the largest n-digit pandigital number is %s' % max_p
def problem(): """ Attempt to solve the problem... """ print 'problem #38' pandigitals = [] for n in xrange(1, 99999): products = [] for i in xrange(1, 20): products.append(str(n * i)) num = int(''.join(products)) if is_pandigital(num): pandigitals.append(num) print max(pandigitals)
def problem(): """ Attempt to solve the problem... """ print 'problem #32' pandigital = {} for a in xrange(1, 9999): for b in xrange(1, 999): p = a * b if pandigital.get(p) is None: m = '%d%d%d' % (a, b, p) if is_pandigital(int(m), zero_full=False): print m pandigital[p] = 0 # Answer: 45228 # current 4943553 print 'the sum of 1-9 pandigitals is: %s' % str(sum(pandigital.keys()))
from common import is_pandigital, get_primes if __name__ == "__main__": """8位和9位的数能被3整除,所以直接找从7位的开始找, 7位的直接从7开头的开始找""" n = 10**6 * 8 PRIMES = set(get_primes(n)) while True: if n in PRIMES and is_pandigital(n, 7): break n -= 1 print(n)
import math from common import is_pandigital if __name__ == "__main__": maximum = 10 ** 10 n = 10000 s = set() for i in range(1, int(math.sqrt(math.sqrt(maximum)))): for j in range(i + 1, min(int(math.sqrt(maximum / i ** 2)), n)): if is_pandigital(int(str(i) + str(j) + str(i * j)), 9): s.add(i * j) print(sum(s))
import math from common import is_pandigital if __name__ == "__main__": maximum = 10**10 n = 10000 s = set() for i in range(1, int(math.sqrt(math.sqrt(maximum)))): for j in range(i + 1, min(int(math.sqrt(maximum / i**2)), n)): if is_pandigital(int(str(i) + str(j) + str(i * j)), 9): s.add(i * j) print(sum(s))
def test_is_pandigital_none_value(): """Tests the is_pandigital function with None value """ assert is_pandigital(None) is False
def test_is_pandigital_zerofill(): """Tests valid zerofill pandigital numbers """ for number in NONZERO_PANDIGITAL_NUMBERS: assert is_pandigital(number, False) is True
def test_is_pandigital_non_zerofill(): """Tests valid non zerofill pandigital numbers""" for number in ZEROFILL_PANDIGITAL_NUMBERS: assert is_pandigital(number, True) is True
from common import is_pandigital, get_primes if __name__ == "__main__": """8位和9位的数能被3整除,所以直接找从7位的开始找, 7位的直接从7开头的开始找""" n = 10 ** 6 * 8 PRIMES = set(get_primes(n)) while True: if n in PRIMES and is_pandigital(n, 7): break n -= 1 print(n)