def test(): assert not is_prime(123) assert not is_prime(132) assert not is_prime(213) assert not is_prime(231) assert not is_prime(312) assert not is_prime(321) assert is_prime(2143) assert is_pandigital(2143) assert 2143 in set(pandigital_primes(digits=4))
def find_pandigitals(): pandigitals = [] for n in xrange(1, 10000): result = '' for f in xrange(1, 10): result += str(n * f) if len(result) > 9: break if is_pandigital(result, 9): print n, '-->', result pandigitals.append(result) return pandigitals
def find_pandigitals(): pandigitals = [] for n in xrange(1, 10000): result = '' for f in xrange(1, 10): result += str(n*f) if len(result) > 9: break if is_pandigital(result, 9): print n, '-->', result pandigitals.append(result) return pandigitals
def find_pandigital_products(): result = set() for a in range(1, 9999): for b in range(a, 9999): x = a * b string = str(a) + str(b) + str(x) if len(string) > 9: break if is_pandigital(string, 9): print a, 'x', b, '=', x result.add(x) return result
def find_pandigital_products(): result = set() # a and b must be less than 5 digits, otherwise the total digits would # exceed 9. (e.g. 1 x 10000 = 10000 is 11 digits.) for a in range(1, 9999): for b in range(a, 9999): x = a * b string = str(a) + str(b) + str(x) # Short circuit if results get too long if len(string) > 9: break if is_pandigital(string, 9): print a, 'x', b, '=', x result.add(x) return result
def find_pandigital_products(): result = set() # a and b must be less than 5 digits, otherwise the total digits would # exceed 9. (e.g. 1 x 10000 = 10000 is 11 digits.) for a in range(1, 9999): for b in range(a, 9999): x = a * b string = str(a) + str(b) + str(x) # Short circuit if results get too long if len(string) > 9: break if is_pandigital(string, 9): print a, "x", b, "=", x result.add(x) return result
def largest_pandigital_concatenated_product(): top = 1 for n in range(1, int('9' * 5)): if not is_semi_pandigital(n): continue cprod = str(n) for k in count(2): next = str(n * k) cprod += next if len(cprod) > 9 or not is_semi_pandigital(next): break elif len(cprod) < 9: continue elif is_pandigital(cprod) and int(cprod) > top: top = int(cprod) return top
def find_pandigital( a_min: int, a_max: int, b_min: int, b_max: int, c_min: int, c_max: int ) -> Set[int]: pandigital_products = set() for a in range(a_min, a_max + 1): b_start = max(b_min, ceil(c_min / a)) b_stop = min(b_max, c_max // a) + 1 for b in range(b_start, b_stop): c = a * b check_str = str(a) + str(b) + str(c) if is_pandigital(check_str): pandigital_products.add(c) return pandigital_products
def p38(): # n == 2 -> x in [5000, 9999] # n == 3 -> x in [100, 333] # n == 4 -> x in [25, 33] # n == 5 -> x in [5, 9] # n == 6 -> x == 3 # n == 9 -> x == 1 largest_pandigital = 0 # ranges to try: (x_min, x_max, n_max) ranges_to_try = [(5000, 9999, 2), (100, 333, 3), (25, 33, 4), (5, 9, 5), (3, 3, 6), (1, 1, 9)] for x_min, x_max, n_max in ranges_to_try: n_stop = n_max + 1 for x in range(x_max, x_min - 1, -1): product = calculate_concatenated_product(x, n_stop) if product < largest_pandigital: break else: if is_pandigital(str(product)): largest_pandigital = product return largest_pandigital
def test_635241879(self): self.assertEqual(is_pandigital('635241879'), True)
def test_empty(self): self.assertEqual(is_pandigital(''), True)
def test_123456789(self): self.assertEqual(is_pandigital('123456789'), True)
def p41() -> None: primes_list = [p for p in primes(10000000) if len(str(p)) in [4, 7]] primes_list.reverse() return next(pandigital_prime for pandigital_prime in primes_list if is_pandigital(str(pandigital_prime)))
def test(): assert '192384576' == concatenated_product(192, 3), concatenated_product( 192, 3) assert '918273645' == concatenated_product(9, 5) assert is_pandigital(concatenated_product(9, 5))
def pandigital_primes(digits=7): for p in primes_upto(int('9' * digits)): if is_pandigital(p): yield p
def test(): assert is_pandigital(978564231) assert is_pandigital(13452) assert is_semi_pandigital(543) assert not is_semi_pandigital(3543)
def is_pandigital_product(a, b, n, k=9): return is_pandigital(str(a) + str(b) + str(n))