A O U T T U O A
+ A T A O - U * T T
---------- ----------
T U * U O * T *
Can you solve these addition and subtraction problems, knowing that AOUT as well as it's reverse TUOA is a prime number?
There are 84 4-digit reversable primes with unique digits (42 pairs). But only one value of AOUT works.
3527 + 3735 = 7262 solves the addition
7253 - 2077 = 5176 solves the subtraction or
7253 - 2177 = 5076 solves the subtraction
Program output:
AOUT found: 3527
-------------
def test(n):
s = str(n)
A = int(s[0])
O = int(s[1])
U = int(s[2])
T = int(s[3])
asum = 2010*A + 101*O + 10*U + 101*T
if asum > 9999:
return False
s_asum = str(asum)
if int(s_asum[0]) != T:
return False
if int(s_asum[1]) != U:
return False
if int(s_asum[3]) != U:
return False
return True
revprimes = []
for n in range(1001,10000,2):
if len(str(n)) != len(set(str(n))):
continue
if isprime(n):
rev_n = int(str(n)[::-1])
if isprime(rev_n):
if n not in revprimes:
revprimes.append(n)
if rev_n not in revprimes:
revprimes.append(rev_n)
revprimes = sorted(revprimes)
for n in revprimes:
if test(n):
print('AOUT found:', n)
|
Posted by Larry
on 2024-01-19 12:13:42 |