from task import parseLine, getMaxScore, getTotalCaloriesCount ## teaspoons = int(sys.argv[1]) ingredients = [] with open("in.txt") as file: for line in file: ingredients.append(parseLine(line)) # part 1 print("part 1:") ingredientsProps = map(lambda (_, props): props, ingredients) print("Max score is {}".format(getMaxScore(teaspoons, ingredientsProps))) # part 2 if len(sys.argv) < 3: print("Missing arguments for part 2") sys.exit(1) calories = int(sys.argv[2]) print("part 2:") def cookiesFilter(ratios, ingredients): return getTotalCaloriesCount(ratios, ingredients) == calories print("Max score with exactely {} calories is {}".format(calories, getMaxScore(teaspoons, ingredientsProps, cookiesFilter)))
## write tests here -- # part 1 # parsing input line = "Sprinkles: capacity 2, durability 0, flavor -2, texture 0, calories 3" output = ("Sprinkles", [2, 0, -2, 0, 3]) t.test("Parsing input", parseLine(line), output) # calculating score t.test("Calculate score", getScore(10, [1, 2, 3]), [10, 20, 30]) t.test("Skip calories 1", getTotalScore([1, 2], [[1, 0], [2, -1]]), 5) t.test("Skip calories 2", getTotalScore([1, 2], [[1, 0], [-2, 1]]), 0) # max score t.test("Calculate max score", getMaxScore(100, [[-1, -2, 6, 3, 8], [2, 3, -2, -1, 3]]), 62842880) # part 2 ## -- end of tests def askYesNo(question): print(question + " [y/n]") yes = set(['yes','y', 'ye', '']) no = set(['no','n']) while True: choice = raw_input().lower() if choice in yes: return True elif choice in no: return False