# AOC Day Script Day XX # Date : 20XX.12.XX # Python Code # Developer : David Bandeira import sys,time from helpingFunctions import * setSampleMode(False) aocDay = identifyDay(sys.argv[0]) aocYear = identifyYear(sys.argv[0]) path = getPath2Data(aocDay,aocYear) filename = getFilename2Data(aocDay) def checkVocals(inputData): retValue = False foundVocal=0 for i in range(0,len(inputData)): letter = inputData[i].lower() if letter == 'a' or letter == 'e' or letter == 'i' or letter == 'o' or letter == 'u': foundVocal+=1 if foundVocal > 2: retValue = True break return retValue def twiceInRow(inputData): retValue=False for i in range(0,len(inputData)-1): if inputData[i] == inputData[i+1]: retValue = True break return retValue def notContain(inputData): retValue=False for i in range(0,len(inputData)-1): checkValue = inputData[i].lower()+inputData[i+1].lower() if checkValue == 'ab' or checkValue == 'cd' or checkValue == 'pq' or checkValue == 'xy': retValue = True break return retValue def doubleTwice(inputData): retValue=False for i in range(0,len(inputData)-1): doubleValue = inputData[i].lower()+inputData[i+1].lower() for j in range(i+2,len(inputData)-1): twiceValue = inputData[j].lower()+inputData[j+1].lower() if doubleValue == twiceValue: retValue = True break if retValue == True: break return retValue def twiceInBetween(inputData): retValue=False for i in range(0,len(inputData)-2): allThree=inputData[i]+inputData[i+1]+inputData[i+2] if inputData[i] == inputData[i+2]: retValue = True break return retValue def taskA (data) -> int: gameScoreA = 0 niceValue = 0 for dataRow in data: dataElems = list(dataRow) is3Vocals = checkVocals(dataElems) if is3Vocals == True: isTwiceInRow = twiceInRow(dataElems) if isTwiceInRow == True: isNotContain = notContain(dataElems) if isNotContain == False : niceValue += 1 gameScoreA = niceValue return gameScoreA def taskB (data) -> int: gameScoreB = 0 niceValue = 0 for dataRow in data: dataElems = list(dataRow) isDoubleTwice = doubleTwice(dataElems) if isDoubleTwice == True: isTwiceInBetween = twiceInBetween(dataElems) if isTwiceInBetween == True: niceValue += 1 gameScoreB = niceValue return gameScoreB def task(task: int,data) -> int: score=0 if task == 1: score = taskA(data) elif task == 2: score = taskB(data) return score def main(): showSampleMode() try: data = open(path+'/'+filename).read().strip().split('\n') except: print ('no inputfile found') print ('please check file %s on path %s' % (filename, path)) quit() st=time.time() print ('Day '+aocDay+': Tasks 1: '+ str(task(1,data))+ ' executation time: ' + str(int((time.time()-st)*1000)) + 'ms') st=time.time() print ('Day '+aocDay+': Tasks 2: '+ str(task(2,data))+ ' executation time: ' + str(int((time.time()-st)*1000)) + 'ms') if __name__ == "__main__": main()