Question: Now let's go directly from evidences to all possible conclusions! Use the graph builder from Q2 on top of the function from Q1 and

Now let's go directly from evidences to all possible conclusions! Use the graph builder from Q2 on top of the function from Q1 and the search function from Q3 to resolve as many hat colors as possible. Note that we start with the state when visited is empty, and is being gradually updated inside of the search function (as we traverse the graph). Write a function resolve_colors (evidences) that takes a list of evidences and, using the function search from Q3, returns a tuple containing a sorted list of gnomes (IDs) in white hats and a sorted list of gnomes (IDs) in black hats (similar to Q1). If a contradiction exists, it should return None. Assume that the graph does not contain cycles (a closed path or a path that starts from a node and ends at the same node). Note: Unlike Q1, you need to consider gnome-pairs in evidence who wear hats in different colors. Sample runs: >>> evidences = [((11, 2), 0), ((3, 6), 2), ((4, >>> print(resolve_colors (evidences)). ([3, 6, 7, 31, 115], [2, 4, 11]) Note that we don't have enough information to derive hat colours for gnomes 21 and 33, so they are not in the returned lists. >>> evidences = [((8, 2), 2), ((3, 6), 2), ((7, 9 >>> print(resolve_colors (evidences)) ([2, 3, 6, 7, 8, 9, 12], []) >>> evidences = [((11, 2), 0), ((3, 6), 2), ((4, >>> print(resolve_colors (evidences)) None >>> evidences = [((11, 2), 0), ((3, 6), 2), ((4, >>> print(resolve_colors (evidences)) None
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
