def test_c18(self): puzzle = m.Puzzle() # 0 = square-on-tip, 1 = triangle nodes = [ m.ShapeNode(0), m.MultipassNode(2), m.ShapeNode(1, terminates=True), m.MultipassNode(2), m.MultipassNode(2), m.ShapeNode(0, terminates=True), m.ShapeNode(1, terminates=True), m.MultipassNode(3), m.ShapeNode(0), m.ShapeNode(1), m.ShapeNode(1), m.ShapeNode(0, terminates=True), ] node_ids = [puzzle.add_node(n) for n in nodes] ls.square_lattice(puzzle, node_ids, 3, 4) solution = s.solve(puzzle) self.assertIsNotNone(solution)
continue nodes = [] for c in split_line[2]: if "a" <= c <= "z": color = ord(c) - ord("a") nodes.append(m.ShapeNode(color, terminates=False)) elif "A" <= c <= "Z": color = ord(c) - ord("A") nodes.append(m.ShapeNode(color, terminates=True)) elif "1" <= c <= "9": count = ord(c) - ord("0") nodes.append(m.MultipassNode(count)) elif c == "_": nodes.append(None) puzzle = m.Puzzle() node_ids = [(puzzle.add_node(n) if n is not None else None) for n in nodes] ls.square_lattice(puzzle, node_ids, width, height) node_ids_to_nodes = {} for (k, v) in enumerate(node_ids): if v is not None: node_ids_to_nodes[v] = k solution = s.solve(puzzle) #print(format_solution_table_calc(solution, node_ids_to_nodes)) print(format_solution_relative_movement(solution, node_ids_to_nodes))