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 eightdigit 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 fourdigit prime numbers. These two primes contain the same four digits, but in a different order, and with no digit repeated. Furthermore if these fourdigit primes are split in half, they each give two twodigit 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 →

GeoffR permalink1234567891011121314151617181920212223242526from itertools import permutationsfrom number_theory import is_prime# list for 4digit 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}")