如何在Python中查找所有出现的非连续子字符串?

如何在Python中查找所有出现的非连续子字符串?,python,string,bioinformatics,combinatorics,biopython,Python,String,Bioinformatics,Combinatorics,Biopython,前提: 我目前正在处理以下问题: 我必须找到字符串中所有子字符串的索引组合,其中子字符串不一定是连续的 我的测试参数: Main_String = ACGGTTAACGTGACGGTTAAGSSGSSTSSTSSASSA Substring = GGTTAA 非连续意味着主字符串中出现的子字符串可能如下所示: GGSTTSAASSS其中子字符串是GGTTAA和主字符串-GGSTTSAASSS 子字符串虽然被随机字符切割(在我们的例子中是S),但仍然可以在主字符串中找到。因此,一个可能的答案是

前提:

我目前正在处理以下问题:

我必须找到字符串中所有子字符串的索引组合,其中子字符串不一定是连续的

我的测试参数:

Main_String = ACGGTTAACGTGACGGTTAAGSSGSSTSSTSSASSA
Substring = GGTTAA
非连续意味着
主字符串中出现的
子字符串可能如下所示:
GGSTTSAASSS
其中子字符串是
GGTTAA
和主字符串-
GGSTTSAASSS

子字符串虽然被随机字符切割(在我们的例子中是S),但仍然可以在主字符串中找到。因此,一个可能的答案是
(格式:主字符串中的字母((索引+1))G(1)G(2)T(4)T(5)a(7)a(8)=1,2,4,5,7,8。
,这对于第一次匹配来说很容易得到。我需要得到所有可能的变化,所以如果我们使用上面的测试参数,正确答案是:

3,4,5,6,7,8和3,12,17,18,19,20和3,15,17,18,19,20等等,最多21,24,27,30,33,36

问题:

我需要一个算法,它可以为我提供给定字符串中非连续子字符串的所有可能变化

问题:

这是我到目前为止的代码,它在一定程度上是有效的,但不会返回所有可能的变体,只返回其中的一些

    dna = ''
counter = -1
dna_subseq = ''
dna_subseq_indexes = []


with open('Rosalind_dna.txt', 'r') as file:
    data = file.read().split('\n')
    for line in data:
        if line == '':
            continue
        if 'Rosalind' in line and counter < 1:
            counter += 1
            continue
        elif 'Rosalind' not in line and counter < 1:
            dna += line
        elif 'Rosalind' not in line and counter >= 1:
            dna_subseq += line

result = 0
dna_subseq_minus_start = dna_subseq[1:]


def find_next(start_parameter, base):
    result_func = dna.find(base, start_parameter)
    if result_func + 1 in dna_subseq_indexes_subcombo:
        if result_func + 1 == 0:
            return
        find_next(start_parameter + 1, base)
    else:
        dna_subseq_indexes_subcombo.append(result_func + 1)
        return


for index, value in enumerate(dna):
    global_start = index
    result = 0
    while result != -1:
        dna_subseq_indexes_subcombo = []
        if value == dna_subseq[0]:
            dna_subseq_indexes_subcombo.append(index + 1)
            Flag = True
            for base in dna_subseq_minus_start:
                if Flag:
                    start = global_start
                    Flag = False
                result = dna.find(base, start)
                if result + 1 in dna_subseq_indexes_subcombo:
                    find_next(start + 1, base)
                else:
                    dna_subseq_indexes_subcombo.append(result + 1)
                    start += 1
            dna_subseq_indexes.append(dna_subseq_indexes_subcombo)
            global_start += 1
        else:
            break


final_result = []
for x in dna_subseq_indexes:
    test = x.copy()
    test.sort()
    if test == x:
        final_result.append(x)
    else:
        continue
print(final_result)
dna=''
计数器=-1
dna_subseq=“”
dna_subseq_索引=[]
以open('Rosalind_dna.txt','r')作为文件:
data=file.read().split('\n')
对于行输入数据:
如果行=='':
持续
如果行和计数器中的“Rosalind”小于1:
计数器+=1
持续
elif‘Rosalind’不在直线上,计数器<1:
dna+=线
elif“Rosalind”不在直线上且计数器>=1:
dna_subseq+=线
结果=0
dna\u subseq\u减去\u start=dna\u subseq[1:]
def find_next(开始_参数,基础):
result\u func=dna.find(base,start\u参数)
如果dna子组索引子组中的结果\u func+1:
如果结果_func+1==0:
返回
查找下一个(起始参数+1,基数)
其他:
dna\u subseq\u index\u subcombo.append(result\u func+1)
返回
对于索引,枚举中的值(dna):
全局启动=索引
结果=0
而结果呢!=-1:
dna_subseq_index_subcombo=[]
如果值==dna_subseq[0]:
dna子目录索引子目录追加(索引+1)
Flag=True
对于dna_subseq_中的碱基减去开始:
如果标志:
开始=全局开始
Flag=False
结果=dna.find(基,开始)
如果dna子组索引子组中的结果+1:
查找下一个(开始+1,基本)
其他:
dna子目录索引子目录追加(结果+1)
开始+=1
dna\u subseq\u index.append(dna\u subseq\u index\u subcombo)
全局_开始+=1
其他:
打破
最终结果=[]
对于dna_subseq_索引中的x:
test=x.copy()
test.sort()
如果测试==x:
最终结果。追加(x)
其他:
持续
打印(最终结果)

我不确定您的算法是否能找到所有解决方案,即使它是固定的。我尝试了这种逻辑: 找到最靠近dna左侧的初始序列,并递归地从右向左搜索所有偏差。这样,解决方案将自动排序

dna        = 'ACGGTTAACGTGACGGTTAAGSSGSSTSSTSSASSA'
dna_len    = len(dna)
dna_subseq = 'GGTTAA'
subseq_len = len(dna_subseq)
count      = 0
print_mode = True # Prints the solutions, set to False to collect them instead

# Finds a single solution starting from the previous one or from a null solution
def find_one_solution(prev_solution, subseq_start, dna_start):
    global dna, dna_subseq, subseq_len, count, mode
    searched   = dna_subseq[subseq_start]
    coll       = prev_solution[:subseq_start]
    subseq_idx = subseq_start

    for i in range(dna_start, len(dna), 1):
        letter = dna[i]
        if letter == searched:
            coll.append(i)
            subseq_idx += 1
        if (subseq_idx == subseq_len): break
        else: searched = dna_subseq[subseq_idx]
    if len(coll) < subseq_len: return None
    count += 1
    if (print_mode): print(coll)
    return coll

# Recursive function
def find_all_solutions(solutions, solution, subseq_start, limit):
    global dna, dna_subseq, subseq_len, print_mode

    for start in range(subseq_len-1, limit-1, -1):
        # last element
        if start == subseq_len-1:
            while True:
                temp = find_one_solution(solution, start, solution[-1]+1)
                if temp == None: break
                else: solution = temp
                if (not print_mode): solutions.append(solution)
        # other elements
        else:
            # finds the next solution
            temp = find_one_solution(solution, start, solution[start]+1)
            if temp == None:
                continue
            else:
                solution = temp
                if (not print_mode): solutions.append(solution)
                # and restarts from end with subseq_start as the left limit
                find_all_solutions(solutions, solution, subseq_len-1, start)


def main():
    all_solutions       = []
    # Finds the initial solution
    initial_solution    = [0] * subseq_len
    initial_solution    = find_one_solution(initial_solution, 0, initial_solution[0])
    if initial_solution == None:
        print("No solution found")
    else:
        if (not print_mode): all_solutions.append(initial_solution)
        # Finds all other solutions
        find_all_solutions(all_solutions, initial_solution, subseq_len-1, 0)
        if (not print_mode): print(all_solutions)
        print("Total count:", count)


if __name__=="__main__":
    main()


#289 solutions found : [[2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 12], [2, 3, 4, 5, 6, 18], [2, 3, 4, 5, 6, 19], [2, 3, 4, 5, 6, 32], [2, 3, 4, 5, 6, 35], [2, 3, 4, 5, 7, 12], [2, 3, 4, 5, 7, 18], [2, 3, 4, 5, 7, 19], [2, 3, 4, 5, 7, 32], [2, 3, 4, 5, 7, 35], [2, 3, 4, 5, 12, 18], [2, 3, 4, 5, 12, 19], [2, 3, 4, 5, 12, 32], [2, 3, 4, 5, 12, 35], [2, 3, 4, 5, 18, 19], [2, 3, 4, 5, 18, 32], [2, 3, 4, 5, 18, 35], [2, 3, 4, 5, 19, 32], [2, 3, 4, 5, 19, 35], [2, 3, 4, 5, 32, 35], [2, 3, 4, 10, 12, 18], [2, 3, 4, 10, 12, 19], [2, 3, 4, 10, 12, 32], [2, 3, 4, 10, 12, 35], [2, 3, 4, 10, 18, 19], [2, 3, 4, 10, 18, 32], [2, 3, 4, 10, 18, 35], [2, 3, 4, 10, 19, 32], [2, 3, 4, 10, 19, 35], [2, 3, 4, 10, 32, 35], [2, 3, 4, 16, 18, 19], [2, 3, 4, 16, 18, 32], [2, 3, 4, 16, 18, 35], [2, 3, 4, 16, 19, 32], [2, 3, 4, 16, 19, 35], [2, 3, 4, 16, 32, 35], [2, 3, 4, 17, 18, 19], [2, 3, 4, 17, 18, 32], [2, 3, 4, 17, 18, 35], [2, 3, 4, 17, 19, 32], [2, 3, 4, 17, 19, 35], [2, 3, 4, 17, 32, 35], [2, 3, 4, 26, 32, 35], [2, 3, 4, 29, 32, 35], [2, 3, 5, 10, 12, 18], [2, 3, 5, 10, 12, 19], [2, 3, 5, 10, 12, 32], [2, 3, 5, 10, 12, 35], [2, 3, 5, 10, 18, 19], [2, 3, 5, 10, 18, 32], [2, 3, 5, 10, 18, 35], [2, 3, 5, 10, 19, 32], [2, 3, 5, 10, 19, 35], [2, 3, 5, 10, 32, 35], [2, 3, 5, 16, 18, 19], [2, 3, 5, 16, 18, 32], [2, 3, 5, 16, 18, 35], [2, 3, 5, 16, 19, 32], [2, 3, 5, 16, 19, 35], [2, 3, 5, 16, 32, 35], [2, 3, 5, 17, 18, 19], [2, 3, 5, 17, 18, 32], [2, 3, 5, 17, 18, 35], [2, 3, 5, 17, 19, 32], [2, 3, 5, 17, 19, 35], [2, 3, 5, 17, 32, 35], [2, 3, 5, 26, 32, 35], [2, 3, 5, 29, 32, 35], [2, 3, 10, 16, 18, 19], [2, 3, 10, 16, 18, 32], [2, 3, 10, 16, 18, 35], [2, 3, 10, 16, 19, 32], [2, 3, 10, 16, 19, 35], [2, 3, 10, 16, 32, 35], [2, 3, 10, 17, 18, 19], [2, 3, 10, 17, 18, 32], [2, 3, 10, 17, 18, 35], [2, 3, 10, 17, 19, 32], [2, 3, 10, 17, 19, 35], [2, 3, 10, 17, 32, 35], [2, 3, 10, 26, 32, 35], [2, 3, 10, 29, 32, 35], [2, 3, 16, 17, 18, 19], [2, 3, 16, 17, 18, 32], [2, 3, 16, 17, 18, 35], [2, 3, 16, 17, 19, 32], [2, 3, 16, 17, 19, 35], [2, 3, 16, 17, 32, 35], [2, 3, 16, 26, 32, 35], [2, 3, 16, 29, 32, 35], [2, 3, 17, 26, 32, 35], [2, 3, 17, 29, 32, 35], [2, 3, 26, 29, 32, 35], [2, 9, 10, 16, 18, 19], [2, 9, 10, 16, 18, 32], [2, 9, 10, 16, 18, 35], [2, 9, 10, 16, 19, 32], [2, 9, 10, 16, 19, 35], [2, 9, 10, 16, 32, 35], [2, 9, 10, 17, 18, 19], [2, 9, 10, 17, 18, 32], [2, 9, 10, 17, 18, 35], [2, 9, 10, 17, 19, 32], [2, 9, 10, 17, 19, 35], [2, 9, 10, 17, 32, 35], [2, 9, 10, 26, 32, 35], [2, 9, 10, 29, 32, 35], [2, 9, 16, 17, 18, 19], [2, 9, 16, 17, 18, 32], [2, 9, 16, 17, 18, 35], [2, 9, 16, 17, 19, 32], [2, 9, 16, 17, 19, 35], [2, 9, 16, 17, 32, 35], [2, 9, 16, 26, 32, 35], [2, 9, 16, 29, 32, 35], [2, 9, 17, 26, 32, 35], [2, 9, 17, 29, 32, 35], [2, 9, 26, 29, 32, 35], [2, 11, 16, 17, 18, 19], [2, 11, 16, 17, 18, 32], [2, 11, 16, 17, 18, 35], [2, 11, 16, 17, 19, 32], [2, 11, 16, 17, 19, 35], [2, 11, 16, 17, 32, 35], [2, 11, 16, 26, 32, 35], [2, 11, 16, 29, 32, 35], [2, 11, 17, 26, 32, 35], [2, 11, 17, 29, 32, 35], [2, 11, 26, 29, 32, 35], [2, 14, 16, 17, 18, 19], [2, 14, 16, 17, 18, 32], [2, 14, 16, 17, 18, 35], [2, 14, 16, 17, 19, 32], [2, 14, 16, 17, 19, 35], [2, 14, 16, 17, 32, 35], [2, 14, 16, 26, 32, 35], [2, 14, 16, 29, 32, 35], [2, 14, 17, 26, 32, 35], [2, 14, 17, 29, 32, 35], [2, 14, 26, 29, 32, 35], [2, 15, 16, 17, 18, 19], [2, 15, 16, 17, 18, 32], [2, 15, 16, 17, 18, 35], [2, 15, 16, 17, 19, 32], [2, 15, 16, 17, 19, 35], [2, 15, 16, 17, 32, 35], [2, 15, 16, 26, 32, 35], [2, 15, 16, 29, 32, 35], [2, 15, 17, 26, 32, 35], [2, 15, 17, 29, 32, 35], [2, 15, 26, 29, 32, 35], [2, 20, 26, 29, 32, 35], [2, 23, 26, 29, 32, 35], [3, 9, 10, 16, 18, 19], [3, 9, 10, 16, 18, 32], [3, 9, 10, 16, 18, 35], [3, 9, 10, 16, 19, 32], [3, 9, 10, 16, 19, 35], [3, 9, 10, 16, 32, 35], [3, 9, 10, 17, 18, 19], [3, 9, 10, 17, 18, 32], [3, 9, 10, 17, 18, 35], [3, 9, 10, 17, 19, 32], [3, 9, 10, 17, 19, 35], [3, 9, 10, 17, 32, 35], [3, 9, 10, 26, 32, 35], [3, 9, 10, 29, 32, 35], [3, 9, 16, 17, 18, 19], [3, 9, 16, 17, 18, 32], [3, 9, 16, 17, 18, 35], [3, 9, 16, 17, 19, 32], [3, 9, 16, 17, 19, 35], [3, 9, 16, 17, 32, 35], [3, 9, 16, 26, 32, 35], [3, 9, 16, 29, 32, 35], [3, 9, 17, 26, 32, 35], [3, 9, 17, 29, 32, 35], [3, 9, 26, 29, 32, 35], [3, 11, 16, 17, 18, 19], [3, 11, 16, 17, 18, 32], [3, 11, 16, 17, 18, 35], [3, 11, 16, 17, 19, 32], [3, 11, 16, 17, 19, 35], [3, 11, 16, 17, 32, 35], [3, 11, 16, 26, 32, 35], [3, 11, 16, 29, 32, 35], [3, 11, 17, 26, 32, 35], [3, 11, 17, 29, 32, 35], [3, 11, 26, 29, 32, 35], [3, 14, 16, 17, 18, 19], [3, 14, 16, 17, 18, 32], [3, 14, 16, 17, 18, 35], [3, 14, 16, 17, 19, 32], [3, 14, 16, 17, 19, 35], [3, 14, 16, 17, 32, 35], [3, 14, 16, 26, 32, 35], [3, 14, 16, 29, 32, 35], [3, 14, 17, 26, 32, 35], [3, 14, 17, 29, 32, 35], [3, 14, 26, 29, 32, 35], [3, 15, 16, 17, 18, 19], [3, 15, 16, 17, 18, 32], [3, 15, 16, 17, 18, 35], [3, 15, 16, 17, 19, 32], [3, 15, 16, 17, 19, 35], [3, 15, 16, 17, 32, 35], [3, 15, 16, 26, 32, 35], [3, 15, 16, 29, 32, 35], [3, 15, 17, 26, 32, 35], [3, 15, 17, 29, 32, 35], [3, 15, 26, 29, 32, 35], [3, 20, 26, 29, 32, 35], [3, 23, 26, 29, 32, 35], [9, 11, 16, 17, 18, 19], [9, 11, 16, 17, 18, 32], [9, 11, 16, 17, 18, 35], [9, 11, 16, 17, 19, 32], [9, 11, 16, 17, 19, 35], [9, 11, 16, 17, 32, 35], [9, 11, 16, 26, 32, 35], [9, 11, 16, 29, 32, 35], [9, 11, 17, 26, 32, 35], [9, 11, 17, 29, 32, 35], [9, 11, 26, 29, 32, 35], [9, 14, 16, 17, 18, 19], [9, 14, 16, 17, 18, 32], [9, 14, 16, 17, 18, 35], [9, 14, 16, 17, 19, 32], [9, 14, 16, 17, 19, 35], [9, 14, 16, 17, 32, 35], [9, 14, 16, 26, 32, 35], [9, 14, 16, 29, 32, 35], [9, 14, 17, 26, 32, 35], [9, 14, 17, 29, 32, 35], [9, 14, 26, 29, 32, 35], [9, 15, 16, 17, 18, 19], [9, 15, 16, 17, 18, 32], [9, 15, 16, 17, 18, 35], [9, 15, 16, 17, 19, 32], [9, 15, 16, 17, 19, 35], [9, 15, 16, 17, 32, 35], [9, 15, 16, 26, 32, 35], [9, 15, 16, 29, 32, 35], [9, 15, 17, 26, 32, 35], [9, 15, 17, 29, 32, 35], [9, 15, 26, 29, 32, 35], [9, 20, 26, 29, 32, 35], [9, 23, 26, 29, 32, 35], [11, 14, 16, 17, 18, 19], [11, 14, 16, 17, 18, 32], [11, 14, 16, 17, 18, 35], [11, 14, 16, 17, 19, 32], [11, 14, 16, 17, 19, 35], [11, 14, 16, 17, 32, 35], [11, 14, 16, 26, 32, 35], [11, 14, 16, 29, 32, 35], [11, 14, 17, 26, 32, 35], [11, 14, 17, 29, 32, 35], [11, 14, 26, 29, 32, 35], [11, 15, 16, 17, 18, 19], [11, 15, 16, 17, 18, 32], [11, 15, 16, 17, 18, 35], [11, 15, 16, 17, 19, 32], [11, 15, 16, 17, 19, 35], [11, 15, 16, 17, 32, 35], [11, 15, 16, 26, 32, 35], [11, 15, 16, 29, 32, 35], [11, 15, 17, 26, 32, 35], [11, 15, 17, 29, 32, 35], [11, 15, 26, 29, 32, 35], [11, 20, 26, 29, 32, 35], [11, 23, 26, 29, 32, 35], [14, 15, 16, 17, 18, 19], [14, 15, 16, 17, 18, 32], [14, 15, 16, 17, 18, 35], [14, 15, 16, 17, 19, 32], [14, 15, 16, 17, 19, 35], [14, 15, 16, 17, 32, 35], [14, 15, 16, 26, 32, 35], [14, 15, 16, 29, 32, 35], [14, 15, 17, 26, 32, 35], [14, 15, 17, 29, 32, 35], [14, 15, 26, 29, 32, 35], [14, 20, 26, 29, 32, 35], [14, 23, 26, 29, 32, 35], [15, 20, 26, 29, 32, 35], [15, 23, 26, 29, 32, 35], [20, 23, 26, 29, 32, 35]]

请注意,我使用基于零的索引是因为它更简单,但如果需要,您可以轻松地将1添加到所有结果中。

我不确定您的算法是否能够找到所有解决方案,即使它是固定的。我尝试了这种逻辑: 找到最靠近dna左侧的初始序列,并递归地从右向左搜索所有偏差。这样,解决方案将自动排序

dna        = 'ACGGTTAACGTGACGGTTAAGSSGSSTSSTSSASSA'
dna_len    = len(dna)
dna_subseq = 'GGTTAA'
subseq_len = len(dna_subseq)
count      = 0
print_mode = True # Prints the solutions, set to False to collect them instead

# Finds a single solution starting from the previous one or from a null solution
def find_one_solution(prev_solution, subseq_start, dna_start):
    global dna, dna_subseq, subseq_len, count, mode
    searched   = dna_subseq[subseq_start]
    coll       = prev_solution[:subseq_start]
    subseq_idx = subseq_start

    for i in range(dna_start, len(dna), 1):
        letter = dna[i]
        if letter == searched:
            coll.append(i)
            subseq_idx += 1
        if (subseq_idx == subseq_len): break
        else: searched = dna_subseq[subseq_idx]
    if len(coll) < subseq_len: return None
    count += 1
    if (print_mode): print(coll)
    return coll

# Recursive function
def find_all_solutions(solutions, solution, subseq_start, limit):
    global dna, dna_subseq, subseq_len, print_mode

    for start in range(subseq_len-1, limit-1, -1):
        # last element
        if start == subseq_len-1:
            while True:
                temp = find_one_solution(solution, start, solution[-1]+1)
                if temp == None: break
                else: solution = temp
                if (not print_mode): solutions.append(solution)
        # other elements
        else:
            # finds the next solution
            temp = find_one_solution(solution, start, solution[start]+1)
            if temp == None:
                continue
            else:
                solution = temp
                if (not print_mode): solutions.append(solution)
                # and restarts from end with subseq_start as the left limit
                find_all_solutions(solutions, solution, subseq_len-1, start)


def main():
    all_solutions       = []
    # Finds the initial solution
    initial_solution    = [0] * subseq_len
    initial_solution    = find_one_solution(initial_solution, 0, initial_solution[0])
    if initial_solution == None:
        print("No solution found")
    else:
        if (not print_mode): all_solutions.append(initial_solution)
        # Finds all other solutions
        find_all_solutions(all_solutions, initial_solution, subseq_len-1, 0)
        if (not print_mode): print(all_solutions)
        print("Total count:", count)


if __name__=="__main__":
    main()


#289 solutions found : [[2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 12], [2, 3, 4, 5, 6, 18], [2, 3, 4, 5, 6, 19], [2, 3, 4, 5, 6, 32], [2, 3, 4, 5, 6, 35], [2, 3, 4, 5, 7, 12], [2, 3, 4, 5, 7, 18], [2, 3, 4, 5, 7, 19], [2, 3, 4, 5, 7, 32], [2, 3, 4, 5, 7, 35], [2, 3, 4, 5, 12, 18], [2, 3, 4, 5, 12, 19], [2, 3, 4, 5, 12, 32], [2, 3, 4, 5, 12, 35], [2, 3, 4, 5, 18, 19], [2, 3, 4, 5, 18, 32], [2, 3, 4, 5, 18, 35], [2, 3, 4, 5, 19, 32], [2, 3, 4, 5, 19, 35], [2, 3, 4, 5, 32, 35], [2, 3, 4, 10, 12, 18], [2, 3, 4, 10, 12, 19], [2, 3, 4, 10, 12, 32], [2, 3, 4, 10, 12, 35], [2, 3, 4, 10, 18, 19], [2, 3, 4, 10, 18, 32], [2, 3, 4, 10, 18, 35], [2, 3, 4, 10, 19, 32], [2, 3, 4, 10, 19, 35], [2, 3, 4, 10, 32, 35], [2, 3, 4, 16, 18, 19], [2, 3, 4, 16, 18, 32], [2, 3, 4, 16, 18, 35], [2, 3, 4, 16, 19, 32], [2, 3, 4, 16, 19, 35], [2, 3, 4, 16, 32, 35], [2, 3, 4, 17, 18, 19], [2, 3, 4, 17, 18, 32], [2, 3, 4, 17, 18, 35], [2, 3, 4, 17, 19, 32], [2, 3, 4, 17, 19, 35], [2, 3, 4, 17, 32, 35], [2, 3, 4, 26, 32, 35], [2, 3, 4, 29, 32, 35], [2, 3, 5, 10, 12, 18], [2, 3, 5, 10, 12, 19], [2, 3, 5, 10, 12, 32], [2, 3, 5, 10, 12, 35], [2, 3, 5, 10, 18, 19], [2, 3, 5, 10, 18, 32], [2, 3, 5, 10, 18, 35], [2, 3, 5, 10, 19, 32], [2, 3, 5, 10, 19, 35], [2, 3, 5, 10, 32, 35], [2, 3, 5, 16, 18, 19], [2, 3, 5, 16, 18, 32], [2, 3, 5, 16, 18, 35], [2, 3, 5, 16, 19, 32], [2, 3, 5, 16, 19, 35], [2, 3, 5, 16, 32, 35], [2, 3, 5, 17, 18, 19], [2, 3, 5, 17, 18, 32], [2, 3, 5, 17, 18, 35], [2, 3, 5, 17, 19, 32], [2, 3, 5, 17, 19, 35], [2, 3, 5, 17, 32, 35], [2, 3, 5, 26, 32, 35], [2, 3, 5, 29, 32, 35], [2, 3, 10, 16, 18, 19], [2, 3, 10, 16, 18, 32], [2, 3, 10, 16, 18, 35], [2, 3, 10, 16, 19, 32], [2, 3, 10, 16, 19, 35], [2, 3, 10, 16, 32, 35], [2, 3, 10, 17, 18, 19], [2, 3, 10, 17, 18, 32], [2, 3, 10, 17, 18, 35], [2, 3, 10, 17, 19, 32], [2, 3, 10, 17, 19, 35], [2, 3, 10, 17, 32, 35], [2, 3, 10, 26, 32, 35], [2, 3, 10, 29, 32, 35], [2, 3, 16, 17, 18, 19], [2, 3, 16, 17, 18, 32], [2, 3, 16, 17, 18, 35], [2, 3, 16, 17, 19, 32], [2, 3, 16, 17, 19, 35], [2, 3, 16, 17, 32, 35], [2, 3, 16, 26, 32, 35], [2, 3, 16, 29, 32, 35], [2, 3, 17, 26, 32, 35], [2, 3, 17, 29, 32, 35], [2, 3, 26, 29, 32, 35], [2, 9, 10, 16, 18, 19], [2, 9, 10, 16, 18, 32], [2, 9, 10, 16, 18, 35], [2, 9, 10, 16, 19, 32], [2, 9, 10, 16, 19, 35], [2, 9, 10, 16, 32, 35], [2, 9, 10, 17, 18, 19], [2, 9, 10, 17, 18, 32], [2, 9, 10, 17, 18, 35], [2, 9, 10, 17, 19, 32], [2, 9, 10, 17, 19, 35], [2, 9, 10, 17, 32, 35], [2, 9, 10, 26, 32, 35], [2, 9, 10, 29, 32, 35], [2, 9, 16, 17, 18, 19], [2, 9, 16, 17, 18, 32], [2, 9, 16, 17, 18, 35], [2, 9, 16, 17, 19, 32], [2, 9, 16, 17, 19, 35], [2, 9, 16, 17, 32, 35], [2, 9, 16, 26, 32, 35], [2, 9, 16, 29, 32, 35], [2, 9, 17, 26, 32, 35], [2, 9, 17, 29, 32, 35], [2, 9, 26, 29, 32, 35], [2, 11, 16, 17, 18, 19], [2, 11, 16, 17, 18, 32], [2, 11, 16, 17, 18, 35], [2, 11, 16, 17, 19, 32], [2, 11, 16, 17, 19, 35], [2, 11, 16, 17, 32, 35], [2, 11, 16, 26, 32, 35], [2, 11, 16, 29, 32, 35], [2, 11, 17, 26, 32, 35], [2, 11, 17, 29, 32, 35], [2, 11, 26, 29, 32, 35], [2, 14, 16, 17, 18, 19], [2, 14, 16, 17, 18, 32], [2, 14, 16, 17, 18, 35], [2, 14, 16, 17, 19, 32], [2, 14, 16, 17, 19, 35], [2, 14, 16, 17, 32, 35], [2, 14, 16, 26, 32, 35], [2, 14, 16, 29, 32, 35], [2, 14, 17, 26, 32, 35], [2, 14, 17, 29, 32, 35], [2, 14, 26, 29, 32, 35], [2, 15, 16, 17, 18, 19], [2, 15, 16, 17, 18, 32], [2, 15, 16, 17, 18, 35], [2, 15, 16, 17, 19, 32], [2, 15, 16, 17, 19, 35], [2, 15, 16, 17, 32, 35], [2, 15, 16, 26, 32, 35], [2, 15, 16, 29, 32, 35], [2, 15, 17, 26, 32, 35], [2, 15, 17, 29, 32, 35], [2, 15, 26, 29, 32, 35], [2, 20, 26, 29, 32, 35], [2, 23, 26, 29, 32, 35], [3, 9, 10, 16, 18, 19], [3, 9, 10, 16, 18, 32], [3, 9, 10, 16, 18, 35], [3, 9, 10, 16, 19, 32], [3, 9, 10, 16, 19, 35], [3, 9, 10, 16, 32, 35], [3, 9, 10, 17, 18, 19], [3, 9, 10, 17, 18, 32], [3, 9, 10, 17, 18, 35], [3, 9, 10, 17, 19, 32], [3, 9, 10, 17, 19, 35], [3, 9, 10, 17, 32, 35], [3, 9, 10, 26, 32, 35], [3, 9, 10, 29, 32, 35], [3, 9, 16, 17, 18, 19], [3, 9, 16, 17, 18, 32], [3, 9, 16, 17, 18, 35], [3, 9, 16, 17, 19, 32], [3, 9, 16, 17, 19, 35], [3, 9, 16, 17, 32, 35], [3, 9, 16, 26, 32, 35], [3, 9, 16, 29, 32, 35], [3, 9, 17, 26, 32, 35], [3, 9, 17, 29, 32, 35], [3, 9, 26, 29, 32, 35], [3, 11, 16, 17, 18, 19], [3, 11, 16, 17, 18, 32], [3, 11, 16, 17, 18, 35], [3, 11, 16, 17, 19, 32], [3, 11, 16, 17, 19, 35], [3, 11, 16, 17, 32, 35], [3, 11, 16, 26, 32, 35], [3, 11, 16, 29, 32, 35], [3, 11, 17, 26, 32, 35], [3, 11, 17, 29, 32, 35], [3, 11, 26, 29, 32, 35], [3, 14, 16, 17, 18, 19], [3, 14, 16, 17, 18, 32], [3, 14, 16, 17, 18, 35], [3, 14, 16, 17, 19, 32], [3, 14, 16, 17, 19, 35], [3, 14, 16, 17, 32, 35], [3, 14, 16, 26, 32, 35], [3, 14, 16, 29, 32, 35], [3, 14, 17, 26, 32, 35], [3, 14, 17, 29, 32, 35], [3, 14, 26, 29, 32, 35], [3, 15, 16, 17, 18, 19], [3, 15, 16, 17, 18, 32], [3, 15, 16, 17, 18, 35], [3, 15, 16, 17, 19, 32], [3, 15, 16, 17, 19, 35], [3, 15, 16, 17, 32, 35], [3, 15, 16, 26, 32, 35], [3, 15, 16, 29, 32, 35], [3, 15, 17, 26, 32, 35], [3, 15, 17, 29, 32, 35], [3, 15, 26, 29, 32, 35], [3, 20, 26, 29, 32, 35], [3, 23, 26, 29, 32, 35], [9, 11, 16, 17, 18, 19], [9, 11, 16, 17, 18, 32], [9, 11, 16, 17, 18, 35], [9, 11, 16, 17, 19, 32], [9, 11, 16, 17, 19, 35], [9, 11, 16, 17, 32, 35], [9, 11, 16, 26, 32, 35], [9, 11, 16, 29, 32, 35], [9, 11, 17, 26, 32, 35], [9, 11, 17, 29, 32, 35], [9, 11, 26, 29, 32, 35], [9, 14, 16, 17, 18, 19], [9, 14, 16, 17, 18, 32], [9, 14, 16, 17, 18, 35], [9, 14, 16, 17, 19, 32], [9, 14, 16, 17, 19, 35], [9, 14, 16, 17, 32, 35], [9, 14, 16, 26, 32, 35], [9, 14, 16, 29, 32, 35], [9, 14, 17, 26, 32, 35], [9, 14, 17, 29, 32, 35], [9, 14, 26, 29, 32, 35], [9, 15, 16, 17, 18, 19], [9, 15, 16, 17, 18, 32], [9, 15, 16, 17, 18, 35], [9, 15, 16, 17, 19, 32], [9, 15, 16, 17, 19, 35], [9, 15, 16, 17, 32, 35], [9, 15, 16, 26, 32, 35], [9, 15, 16, 29, 32, 35], [9, 15, 17, 26, 32, 35], [9, 15, 17, 29, 32, 35], [9, 15, 26, 29, 32, 35], [9, 20, 26, 29, 32, 35], [9, 23, 26, 29, 32, 35], [11, 14, 16, 17, 18, 19], [11, 14, 16, 17, 18, 32], [11, 14, 16, 17, 18, 35], [11, 14, 16, 17, 19, 32], [11, 14, 16, 17, 19, 35], [11, 14, 16, 17, 32, 35], [11, 14, 16, 26, 32, 35], [11, 14, 16, 29, 32, 35], [11, 14, 17, 26, 32, 35], [11, 14, 17, 29, 32, 35], [11, 14, 26, 29, 32, 35], [11, 15, 16, 17, 18, 19], [11, 15, 16, 17, 18, 32], [11, 15, 16, 17, 18, 35], [11, 15, 16, 17, 19, 32], [11, 15, 16, 17, 19, 35], [11, 15, 16, 17, 32, 35], [11, 15, 16, 26, 32, 35], [11, 15, 16, 29, 32, 35], [11, 15, 17, 26, 32, 35], [11, 15, 17, 29, 32, 35], [11, 15, 26, 29, 32, 35], [11, 20, 26, 29, 32, 35], [11, 23, 26, 29, 32, 35], [14, 15, 16, 17, 18, 19], [14, 15, 16, 17, 18, 32], [14, 15, 16, 17, 18, 35], [14, 15, 16, 17, 19, 32], [14, 15, 16, 17, 19, 35], [14, 15, 16, 17, 32, 35], [14, 15, 16, 26, 32, 35], [14, 15, 16, 29, 32, 35], [14, 15, 17, 26, 32, 35], [14, 15, 17, 29, 32, 35], [14, 15, 26, 29, 32, 35], [14, 20, 26, 29, 32, 35], [14, 23, 26, 29, 32, 35], [15, 20, 26, 29, 32, 35], [15, 23, 26, 29, 32, 35], [20, 23, 26, 29, 32, 35]]

请注意,我使用基于零的索引是因为它更简单,但如果需要,您可以轻松地将1添加到所有结果中。

您能指出缺失的结果吗?3、10、11、17、19、20-其中每个数字都是主字符串的相应索引+1,可能还有更多,但这一个是肯定的,您能指出缺失的结果吗?3、10、11、17,19,20-其中每个数字都是主_字符串的相应索引+1,可能还有更多,但这一个是肯定的谢谢!这是一种我以前从未考虑过的方法,我觉得它非常有趣!我试着用一个样本数据集运行它,因为它太大,不能放在这里,所以我会把它放到一个粘贴箱中。不幸的是,我遇到了内存错误,目前无法确认解决方案是否正确,尽管在查看代码和测试示例之后,我相信它是正确的。我现在就要处理内存错误了,但是如果你有任何关于如何处理它的提示,我会非常高兴:)我使用的示例数据集:我认为任何个人计算机都没有足够的内存来处理该链接中给出的情况,特别是在使用列表的python中(我猜它可能会消耗几十GB的内存)。一种可能的解决方案是将结果写入文件,而不是将其保存在内存中。测试后,
find_one_解决方案
似乎能够找到没有任何问题的单个解决方案。当在最后一个容器中累积解决方案时,问题开始出现(在下一个注释中继续)。如果不是将每个解决方案推送到列表中,而是从\u start
查找\u所有\u解决方案\u将其存储在文件中,则内存问题将得到解决(检查文件是否变大,因为我不知道会找到多少解决方案,可能很多…)。之后,另一个问题可能是整个过程所消耗的时间。实施一种进度指标应该是一个好主意,这样你可以在几分钟或几小时后进行推断,如果计算有可能