By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.
By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property.
Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family.
(In other words: the smallest prime of the family contains one digit, or a larger number of identical digits, which, when replaced with another digit or other identical digits, fills out the family to eight members.) Project Euler problem 51
I found two 6-digit families, interestingly, each involved the first digit being replaced. In the first case, 0 was not one of the replacement digits so it is a valid solution; but the second case did have one of the 8 family members with a leading zero, so this one is rejected.
x2x3x3 [121313, 222323, 323333, 424343, 525353, 626363, 828383, 929393]
x4x6x9 [40609, 141619, 242629, 343639, 444649, 646669, 747679, 949699] REJECTED since 40609 is only 5 digits
120383 is the smallest prime which fits the pattern x2x3x3 (if the x's do not need to be the same) and this is the solution for the smallest prime that has a family of 8 by replacing 3 of the digits as instructed.
But I think the intended solution is the first member of the family which is 121313.
------------------------
import sympy as sp
digits = 6
subs = 3
from itertools import combinations
patterns=[]
for comb in combinations([i for i in range(digits-1)],subs):
patterns.append(list(comb))
primes = []
for z in sp.primerange(10**(digits - 2), 10**(digits)):
primes.append(z)
bases = []
for base in range(10**(digits-subs-1)+1,10**(digits-subs),2):
if base%10 == 5:
continue
bases.append(base)
solutions = []
for b in bases:
sb = str(b)
for p in patterns:
prime_count = 0
mypattern = []
base_dig_count = 0
for position in range(digits):
if position in p:
mypattern.append('x')
else:
mypattern.append(sb[base_dig_count])
base_dig_count +=1
st_my_pat = ''.join(mypattern)
win_list = []
for d in '0123456789':
n = int(st_my_pat.replace('x',d))
if n in primes:
prime_count += 1
win_list.append(n)
if prime_count > 7:
solutions.append([st_my_pat, win_list])
print(st_my_pat, win_list)
|
Posted by Larry
on 2024-02-17 12:51:46 |