Example #1
0
 def formatToWordsSize(array:list,minSize:int,maxSize:int):
     result = ArrayList()
     maxSize = max(maxSize,minSize)
     for word in array:
         if minSize <= word.__len__() <= maxSize:
             result.append(word)
     return result
Example #2
0
def readListFromFile(filePath)->list:
    file = open(filePath,'r')
    array = ArrayList()
    for line in file.readlines():
        if line.__len__()>1:

            array.append(stringReplace(line,'\n'))
    return array
Example #3
0
    def generateAllPossibleIndexes(indexCount:int,maxLength:int)->list:
        finalArray = ArrayList()

        for i in range(0,indexCount):
            finalArray.append(i)
        array = finalArray.copy()

        for i in range(0,maxLength-1):
            finalArray = IndexGenerator.arrayObjectCrossProduct(finalArray,array)

        return finalArray
Example #4
0
    def generateIndexList(size:int,maxLength:int)->list:
        maxLength = min(size,maxLength)
        # print("MaxLen:"+str(maxLength))
        indexArrayList = dict()
        indexArray = ArrayList()

        for i in range(0, size):
            indexArray.append(i)
        for i in range(0, size):
            newArray = ArrayList()
            IndexGenerator.__go(indexArrayList, newArray.copy(), indexArray.copy(), i, maxLength)
        array = ArrayList()
        for each in indexArrayList.values():
            array.append(each)
        array.sort()
        return array
Example #5
0
    def arrayObjectCrossProduct(array:list,objects:list):
        newArray = ArrayList()
        for ar in array:
            for ob in objects:
                newObject = list()
                try:
                    newObject.extend(ar)
                except TypeError:
                    newObject.append(ar)
                try:
                    newObject.extend(ob)
                except TypeError:
                    newObject.append(ob)

                newArray.append(newObject)

        return newArray
Example #6
0
    def __go(indexArrayList: dict, current: ArrayList, left: ArrayList, i:int, maxLength:int):
        length = current.__len__()

        if length >= maxLength:
            indexArrayList.setdefault(current.__str__(),current)
            # Debug.print("add:"+current.__str__())
            return
        else:
            current.append(left.pop(i))
            length = left.__len__()
            # Debug.print("Cur:" + current.__str__() + " Left:" + left.__str__() + " len =" + str(length), end="")
            # Debug.print(" index:" + str(i))
            a = 0
            if a<length:
                while a < length:
                    IndexGenerator.__go(indexArrayList,current.copy(), left.copy(), a, maxLength)
                    a += 1
            else:
                indexArrayList.setdefault(current.__str__(), current)
                # Debug.print("add:" + current.__str__())
                return
Example #7
0
    class IndexArrayWithIncrements:
        def __init__(self,indexCount:int, maxLength:int,startingValue=0):
            self.maxValue = indexCount-1
            self.maxLength = maxLength
            self.array = ArrayList()
            for i in range(0,maxLength):
                self.array.append(0)
            self.increment(startingValue)

        def __bump(self):
            currentIndex = self.maxLength-1

            while not currentIndex<0:
                if self.array[currentIndex] < self.maxValue:
                    self.array[currentIndex]+=1
                    return
                else:
                    self.array[currentIndex] = 0
                currentIndex+=-1

        def increment(self, amount=1):
            for i in range(0,amount):
                self.__bump()

        def containsIndexPair(self):
            for i in range(1,self.maxLength):
                if self.array[i-1] == self.array[i]:
                    return True
            return False

        def returnValueByAlphabet(self,alphabet:str):
            string=""
            for i in self.array:
                string+= alphabet[i]
            return string

        def getPossibleVariationCount(self):
            return Math.math.pow(self.maxValue+1,self.maxLength)