Automatches

import os

def combine(ArrayList,count):
    ArrayList=list(ArrayList)
    newArrayList=[]
    for i in range(0,ArrayList.__len__()-count+1):
        LackArray=ArrayList
        CurrentValue=LackArray[i]
        for tube in range(i+1,ArrayList.__len__()-count+2):
            TotalValue=CurrentValue
            Process=str(i)
            newArray={}
            for c in range(0,count-1):
                index=tube+c
                TotalValue=TotalValue+LackArray[index]
                Process=Process+"+"+str(index)

            newArray[str(TotalValue)]=Process
            newArrayList.append(newArray)
    return newArrayList


def generateAll(ArrayList):
    All=[]
    for i in range(2,ArrayList.__len__()+1):
        All=All+combine(ArrayList,i)

    return All

def generateNewLackArray(ArrayList,count,TargetArray):
    ArrayList=list(ArrayList)
    newArrayList=[]
    matchResult=[]
    # i=0
    for i in range(0,ArrayList.__len__()-count+1):
        LackArray = ArrayList
        if ArrayList[i]=="N":
            continue

        CurrentValue=LackArray[i]
        for tube in range(i+1,ArrayList.__len__()-count+2):
            TotalValue=CurrentValue
            Process=str(i+1)
            newArray={}
            for c in range(0,count-1):

                index=tube+c
                if LackArray[index]=="N":
                    continue

                TotalValue=TotalValue+LackArray[index]
                Process=Process+"+"+str(index+1)

            newArray[str(TotalValue)]=Process
            if TotalValue in TargetArray:

               result={}
               result[Process]=list(TargetArray).index(TotalValue)+1
               matchResult.append(result)
               TargetArray[(list(TargetArray).index(TotalValue))]="N"

               popArray=Process.split("+")
               popArray.reverse()
               for p in popArray:
                   ArrayList[(int(p)-1)]="N"
               break


        # i+=1


    print(ArrayList)
    print(TargetArray)
    return matchResult,ArrayList,TargetArray


def getArrayList(path):
    if not os.path.exists(path):
        return []
    with open(path,"r") as reader:
        ArrayList=reader.read().split("\n")
        for i in range(0,ArrayList.__len__()):
            if ArrayList[i]=="":
                ArrayList.pop(i)
        return ArrayList

def moretimes(ArrayList,TargetList):
    ArrayList=list(ArrayList)
    TargetList=list(TargetList)
    Result=[]
    for count in range(2,ArrayList.__len__()-1):
        matchResult,ArrayList,TargetList= generateNewLackArray(ArrayList,count,TargetList)
        Result=Result+matchResult
    return Result




if __name__=="__main__":
    a=[8,1,2,3,4,1,2,3,4,1,2,1,1,1,1,1,1,1]
    b=[1,3,7,6,7]
    print(moretimes(a,b))
    # print(getArrayList("1.txt"))
    # b=[6,10,15]

    # print(generateAll(a))
    # print(generateNewLackArray(a,3,b))

 

posted on 2019-10-17 23:23  Zeech_Lee  阅读(143)  评论(0编辑  收藏  举报

导航