Determine the smallest pair of twin primes A and B, such that when concatenated, A and B will contain all 10 decimal digits.
My original code was just looking for the smallest; it did not properly account for all the conditions.
I corrected it and removed the break statement so now it finds the same 69 solutions (of 8-digit numbers) as Charlie found.
At first I was forcing the smaller 8-digit prime to have no repeat digits, but there is at least one solution that ends in a double 9, so I modified to account for that.
Ran in about 4 seconds.
-----
for i in range(10000009,100000000,10):
s = str(i)
if '1' in s:
continue
if s[6] == '9':
setlength = 7
else:
setlength = 8
if len(set(s)) != setlength:
continue
if str(int(s[6])+1) in s:
continue
if isprime(i) and isprime(i+2):
if len(set(str(i)+str(i+2)))==10:
print('({}, {})'.format(i, i+2))
|
Posted by Larry
on 2023-10-20 13:37:20 |