0

我有一个与 Lindenmayer 系统相关的项目。由于算法,我坚持了一些事情。我想在两个字符串之间创建一个规则查找器,例如 Gen1: ABAABABA Gen2: ABAABABAABAAB

输出应为: rule1: A, AB rule2: B, A

这条规则应该用于任何有关系的字符串。

我创建了一些他们在字符串中查找常量的方法,例如:“A”、“B” 但是,我不知道如何查找规则。

  def compare(newcode, trialrule1, trialrule2):

        if newcode==Genx2:
            print('rules are tru')
            print(trialrule1)
            print(trialrule2)
            sys.exit()
        else:

            return newcode, trialrule1, trialrule2


def rulefinder():

 rul1 = Genx2[0]
 rul2 = Genx2[1]
 code = ""
 for y in range(1,len(Genx2)-1):
     for x in range (0,len(Genx2)-1):


                for cha in Genx1:
                    if cha==repetitivestring1[0]:

                        code +=AddingToNewString2(rul1)


                    elif cha==repetitivestring1[1]:

                        code +=AddingToNewString2(rul2)


                print(code)
                compare(code, rul1, rul2)
                rul1=AddingToNewString2(Genx2[x+1])

     rul2=AddingToNewString2(Genx2[y+1])

def AddingToNewString2(rules):
   NewString = ""

   NewString = NewString + rules

   return NewString
4

0 回答 0