def test1(self): p = Problem('input2019/a_example.txt') s = Solution(p) s.add_horizontal(1) s.add_vertical(1, 2) s.add_horizontal(3) self.assertFalse(s.check_correctness())
def solve_tobi(p: Problem): s = Solution(p) current = None remaining_pics = [] for i in range(p.num_pics): if (p.orientation[i] != 'H'): continue # for now only horizontal # init first if (current == None): current = p.tags[i] s.add_horizontal(i) remaining_pics = set(range(i + 1, p.num_pics)) best_candidate = -1 best_score = -1 for j in remaining_pics: candidate_id = j if (p.orientation[candidate_id] != 'H'): continue # for now only horizontal candidate = p.tags[candidate_id] score_candidate = score(current, candidate) if (score_candidate > best_score): best_candidate = candidate_id best_score = score_candidate if best_candidate != -1: s.add_horizontal(best_candidate) remaining_pics = remaining_pics - set([best_candidate]) return s
def b_test_solve(p): g = [[] for i in range(N)] used = [False for i in range(N)] sys.setrecursionlimit(N * 10) tags_ids = dict() solution = Solution(p) def dfs(v): used[v] = True solution.add_horizontal(v) for u in g[v]: if used[u] == False: # pass dfs(u) for pic_id in tqdm.tqdm(range(p.num_pics)): for tag in p.tags[pic_id]: if tag not in tags_ids: tags_ids[tag] = [] tags_ids[tag].append(pic_id) for tag, tag_id_list in tags_ids.items(): assert (len(tag_id_list) <= 2) if len(tag_id_list) == 2: g[tag_id_list[0]].append(tag_id_list[1]) g[tag_id_list[1]].append(tag_id_list[0]) v = -1 for i in range(N): if used[i] == False: v = i while (True): used[v] = True found = False solution.add_horizontal(v) for u in g[v]: if used[u] == False: v = u found = True break if found == False: break return solution
def test4(self): p = Problem('input2019/a_example.txt') s = Solution(p) s.add_horizontal(0) s.add_horizontal(3) self.assertTrue(s.check_correctness())