Exemple #1
0
def longest_path(regex: str, count_farther_away_than: int = 1000):
    doors = build_maze(regex).doors
    opened_doors: Set[Tuple[Tuple[int, int], Tuple[int, int]]] = set()
    positions: Set[Tuple[int, int]] = {(0, 0)}
    rooms_near: Set[Tuple[int, int]] = set()
    rooms_all: Set[Tuple[int, int]] = set()
    counter = 0
    while doors != opened_doors:
        new_positions = set()
        for position in positions:
            for door in _doors_from_position(position):
                if door not in opened_doors and door in doors:
                    opened_doors.add(door)
                    new_positions.add(door[0])
                    new_positions.add(door[1])
                    rooms_all.add(door[0])
                    rooms_all.add(door[1])
                    if counter < count_farther_away_than - 1:
                        rooms_near.add(door[0])
                        rooms_near.add(door[1])
        positions = new_positions
        counter += 1
    return counter, len(rooms_all) - len(rooms_near)
Exemple #2
0
 def test_build_maze_a_or_bc(self):
     self.assertEqual(str(build_maze("^NN|(EE)SS$")), _read_file("example-a_or_bc"))
Exemple #3
0
 def test_build_maze_example_3(self):
     self.assertEqual(
         str(build_maze("^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$")),
         _read_file("example-3"),
     )
Exemple #4
0
 def test_build_maze_example_2(self):
     self.assertEqual(
         str(build_maze("^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$")),
         _read_file("example-2"),
     )
Exemple #5
0
 def test_build_maze_example_1(self):
     self.assertEqual(str(build_maze("^ENWWW(NEEE|SSE(EE|N))$")), _read_file("example-1"))
Exemple #6
0
 def test_build_maze_ab_or_c(self):
     self.assertEqual(str(build_maze("^NN(EE)|SS$")), _read_file("example-ab_or_c"))