def test_get_happiness_delta_for_person(self): example = """Alice would lose 79 happiness units by sitting next to Carol. Alice would lose 2 happiness units by sitting next to Bob. Carol would lose 62 happiness units by sitting next to Alice.""" parsed = day13.parse_input(example) order = ['Alice', 'Bob', 'Carol'] expect = -79 + -2 self.assertEqual(expect, day13.get_happiness_delta_for_person('Alice', parsed, order))
def test_input(self): graph = day13.parse_input(day13.INPUT_STRING) best = None for path in [p for p in day9.get_all_paths(graph) if all([loc in p for loc in graph.keys()])]: total = 0 for person in path: h = day13.get_happiness_delta_for_person(person, graph, path) total += h if total > best: best = total self.assertEqual(0, best)