import sys if len(sys.argv) < 2: print("Missing arguments") sys.exit(1) 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:")
import sys from task import parseLine, findAunt, Aunt, findAuntPartTwo ## aunts = [] with open("in.txt") as file: for line in file: aunt = parseLine(line) aunts.append(aunt) sue = Aunt(-1) sue.addProp("children", 3) sue.addProp("cats", 7) sue.addProp("samoyeds", 2) sue.addProp("pomeranians", 3) sue.addProp("akitas", 0) sue.addProp("vizslas", 0) sue.addProp("goldfish", 5) sue.addProp("trees", 3) sue.addProp("cars", 2) sue.addProp("perfumes", 1) # part 1 print("part 1:") match = findAunt(aunts, sue) if match != None: print("Found aunt Sue: {}".format(match.id)) else:
ARGS_COUNT = 0 if len(sys.argv) < ARGS_COUNT: print("Missing arguments") sys.exit(1) from task import parseLine, findOptimum, buildStructure, addAmbivalentPerson ## result = 0 seating = [] with open("in.txt") as file: for line in file: seating = seating + [parseLine(line)] # part 1 structure = buildStructure(seating) (result, permutation) = findOptimum(structure) print("The result of 'part 1' is '\033[1;33m{}\033[1;m' (seating is {})".format(result, permutation)) # part 2 structure = addAmbivalentPerson(buildStructure(seating)) (result, permutation) = findOptimum(structure) print("The result of 'part 2' is '\033[1;33m{}\033[1;m' (seating is {})".format(result, permutation)) ## sys.exit(0)
import sys sys.path.insert(0, "../") from tester import Tester t = Tester() ## from task import parseLine, getScore, getTotalScore, getMaxScore ## 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', ''])
("A", "C", 12), ("C", "A", -3), ("B", "C", 6), ("C", "B", -1), ("A", "D", 0), ("B", "D", 9), ("C", "D", -14), ("D", "A", -100), ("D", "B", 23), ("D", "C", 14), ] structure = buildStructure(happinessDeclaration) t.test( "David would lose 53 happiness units by sitting next to Carol.", parseLine("David would lose 53 happiness units by sitting next to Carol."), ("David", "Carol", -53), ) t.test( "David would gain 43 happiness units by sitting next to Alice.", parseLine("David would gain 43 happiness units by sitting next to Alice."), ("David", "Alice", 43), ) t.test( "generate permutations", generatePermutations(["a", "b", "c"]), [["a", "b", "c"], ["a", "c", "b"], ["b", "a", "c"], ["b", "c", "a"], ["c", "a", "b"], ["c", "b", "a"]], ) t.test( "build data structure", structure,