Is there any way I could optimize this number search with multiprocessing?

44 views Asked by At
from perms import perms


def dfac(n):
    potential_factors = [9, 8, 7, 6, 4, 3, 2, 1]
    factors = [9, 8]
    n //= 72
    while n != 1:
        for f in potential_factors:
            if n % f == 0 and f != 1:
                factors.append(f)
                n //= f
                break
            elif f != 1:
                potential_factors = potential_factors[1:]
                break
            else:
                return ['f']
    return factors[::-1]


##############################################################################

version = 1

perms_length = len(perms)

index = 17701


def search(start: int):
    for ones in range(start, index + 9144 * version, 9):  # ignore this weird range
        i = 1
        for p in perms:
            if len(dfac(int('1' * ones + p))) == 1:
                print(f'{ones} ({i} / {perms_length})')
            else:
                cool = f'\n\n\nOnes: {ones}\nPerm: {p}\n\n\n'
                print(cool)
                exit()
            i += 1


search(20077)

perms is a list of 113600 permutations of a number (as strings). I'm appending a bunch of ones to the beginning of each permutation and trying to factor each into single-digit factors (dfac). dfac returns fail string in list ['f'] if it fails to factor the number into any combination of [9, 8, 7, 6, 4, 3, 2]. How could I split this up with multiprocessing to make this go faster?

0

There are 0 answers