(Python) #v2.7.13, see LINKS to run it online.
#semitest(number, 0) returns True iff number is a semiprime
def semitest(number, factors):
if number != 2:
for p in [2] + range(3, int(number ** 0.5) + 1, 2):
if number % p == 0:
if factors < 2:
return semitest(number / p, factors + 1)
else:
return False
if factors == 1:
return True
else:
return False
#main function
def doIt(base):
#initialization
numbers = [[]]
indices_list = [[]]
i = 0
for number in range(1, base):
if semitest(number, 0):
numbers[0].append(number)
indices_list[0].append([i])
i += 1
#numbers[0] is the digit pool
#numbers[-1] is to be appended to
#numbers[-2] is for reference to past numbers
#indices_list records the indices of numbers
numbers.append([])
indices_list.append([])
#main while loop, go until there are no numbers left in the sequence
indices = [0, 0]
while len(numbers[-2]) > 0:
#test number
if indices[:-1] in indices_list[-2]:
if indices[1:] in indices_list[-2]:
#little-endian
number = 0
power = 0
for index in indices:
number += numbers[0][index] * base ** power
power += 1
if semitest(number, 0):
numbers[-1].append(number)
indices_list[-1].append(indices[:])
#increment indices
for i in range(len(indices)):
indices[i] += 1
if indices[i] == len(numbers[0]):
indices[i] = 0
if i == len(indices) - 1:
indices = [0] * len(indices) + [0]
numbers.append([])
indices_list.append([])
else:
break
#print results after while loop has run
print base, sum(numbers, [])
print numbers
#call main function
doIt(10)
(Python)
from sympy import factorint
for n in range(1, 10):
ylist = []
for i in (4, 6, 9):
for x in xlist:
if sum(factorint(10*x+i).values()) == 2 and (10*x+i) % 10**n in xlist:
ylist.append(10*x+i)
elif sum(factorint(x+i*10**n).values()) == 2 and (x//10+i*10**(n-1)) in xlist:
ylist.append(x+i*10**n)
xlist = set(ylist)
if not len(xlist):
break
|