New Scientist Enigma 509 – Banking on a Prime
by Paul de Sa
From Issue #1661, 22nd April 1989
I have two accounts at Midloids bank, both with unusual eight-digit account numbers, which are made up of a combination of all odd digits. If either of the account numbers is split in half it gives two four-digit prime numbers. These two primes contain the same four digits, but in a different order, and with no digit repeated. Furthermore if these four-digit primes are split in half, they each give two two-digit prime numbers. If, for both numbers, the prime formed from the first four digits is larger than the prime formed from the second four digits, what are the numbers of my accounts?
2 Comments
Leave one →
-
Brian Gladman permalink123456789101112131415161718from itertools import combinationsfrom number_theory import is_prime# two digit primes with all their digits odd and differentpr2 = {x + y for x in '13579' for y in '13579' if x != y and is_prime(int(x + y))}# four digit values formed by concatenating two of the above primes# and such that they are also primes and have four different digitspr4 = {x + y for x in pr2 for y in pr2 if is_prime(int(x + y)) andnot set(x).intersection(y)}# eight digit values formed by concatenating the above four digit# primes such that the latter have the same digits with the first# larger than the secondacn = [b + a for a, b in combinations(sorted(pr4), 2) if set(a) == set(b)]print(f"The account numbers are {' and '.join(sorted(acn))}.")
-
GeoffR permalink1234567891011121314151617181920212223242526from itertools import permutationsfrom number_theory import is_prime# list for 4-digit primes with odd digitspod4 = []for p in permutations('13579', 4):a, b, c, d = pn = int(a + b + c + d)if is_prime(n):pod4.append(n)# select two four digit primesfor p1, p2 in permutations(pod4, 2):if p1 < p2: continueacc_no = int(str(p1) + str(p2))# the two primes have the same digits in a different orderif set(str(p1)) == set(str(p2)):a, b, c, d, e, f, g, h = str(acc_no)# split the account number into four two digit numbersp3, p4, p5, p6 = int(a + b), int(c + d) ,int(e + f), int(g + h)if all(is_prime(x) for x in (p3, p4, p5, p6)):print(f"Account number = {acc_no}")