def main(): with open("01/input.txt", encoding="UTF-8") as file: measurements = fileToList(file, "\n") previousMeasurement = measurements[0] counter = 0 for measurement in measurements: if measurement > previousMeasurement: counter += 1 previousMeasurement = measurement print(counter)
def simpleTest(filepath): lines = utils.fileToList(filepath) assert((len(lines) % 2) == 0) for i in range(len(lines)//2): input_str = lines[2*i] gold = numpy.fromstring(lines[2*i + 1], dtype=int, sep=" ").tolist() estimated_counts = extractItemCounts(input_str) if(gold != estimated_counts): print("Error in input: ", input_str) print("Gold = ", countsToString(gold)) print("Estimated = ", countsToString(estimated_counts))
def main(): with open("01/input.txt", encoding="UTF-8") as file: measurements = fileToList(file, "\n") previousMeasurement = sum(measurements[0:3]) counter = 0 for i in range(len(measurements)): if (i + 2 > len(measurements)): break window = measurements[i:i + 3] measurement = sum(window) if measurement > previousMeasurement: counter += 1 previousMeasurement = measurement print(counter)
def testResponses(input_file): lines = utils.fileToList(input_file) for line in lines: print("Input = ", line) estimated_counts = extractItemCounts(line) words = tokenize(line) words_lower = [word.lower() for word in words] if(terminatedConversation(line, words, words_lower)): print("Are you suggesting we've come to a deal?") continue compromise = checkCompromise(line, words, words_lower) if(compromise != None): if compromise[0] == [0]*len(items) and compromise[1] == [0]*len(items): print("It seems like you wanted a compromise but I din't know what you want to give me " + "or what you want in return") continue if compromise[0] == [0]*len(items): print("It seems like you wanted a compromise but didn't give me anything in return for " + "you taking " + countsToString(compromise[1])) continue if compromise[1] == [0]*len(items): print("It seems like you wanted a compromise but didn't ask for anything in return for " + "giving me " + countsToString(compromise[0])) continue print("Are you suggesting to give me " + countsToString(compromise[0]) + " in return for " + "you taking " + countsToString(compromise[1])) continue '''if (input is a rejection of offer): print("You didn't want to take up my offer?") if (input is an affirmation of offer): print("You agree? I'll end the negotiation") if (input is a request): print("Are you asking for: " + countsToString(estimated_counts) + "?")''' print("Are you asking for: " + countsToString(estimated_counts) + "?")
def test_fileToList(self): self.assertEqual(utils.fileToList('test_resources/names.txt'), ['Linus Thorvalds', 'Bill Gates', 'Steve Jobs'])