Esempio n. 1
0
 def test_3_option_branching(self):
     self.assertEqual(
         BranchedSection(StraightSection("S"), [
             StraightSection("W"),
             StraightSection("E"),
             StraightSection("S")
         ], StraightSection("S")), parse_input_for_brackets("^S(W|E|S)S$"))
Esempio n. 2
0
 def test_nested_brackets_branch_2(self):
     self.assertEqual(
         BranchedSection(StraightSection("N"), [
             StraightSection("W"),
             BranchedSection(StraightSection("S"),
                             [StraightSection("N"),
                              StraightSection("S")], StraightSection("W"))
         ], StraightSection("E")),
         parse_input_for_brackets("^N(W|S(N|S)W)E$"))
Esempio n. 3
0
def scan_input(radius: int, string_input: str) -> Map:

    brackets = parse_input_for_brackets(string_input)
    map_layout = initiate_map(radius)
    locations = {Location(radius, radius)}

    map_layout.follow_commands(locations, brackets)

    return map_layout
Esempio n. 4
0
 def test_two_brackets(self):
     self.assertEqual(
         BranchedSection(
             StraightSection("N"),
             [StraightSection("W"),
              StraightSection("E")],
             BranchedSection(StraightSection("S"),
                             [StraightSection("N"),
                              StraightSection("S")], StraightSection("W"))),
         parse_input_for_brackets("^N(W|E)S(N|S)W$"))
Esempio n. 5
0
 def test_no_brackets(self):
     self.assertEqual(StraightSection("NWES"),
                      parse_input_for_brackets("^NWES$"))
Esempio n. 6
0
    brackets = parse_input_for_brackets(string_input)
    map_layout = initiate_map(radius)
    locations = {Location(radius, radius)}

    map_layout.follow_commands(locations, brackets)

    return map_layout


if __name__ == "__main__":
    with open("../../data/day20.txt", "r") as file:
        input_string = file.readline()

    SIZE = 52

    actual_brackets = parse_input_for_brackets(input_string)

    actual_map_layout = initiate_map(SIZE)

    initial_locations = {Location(SIZE, SIZE)}

    actual_map_layout.follow_commands(initial_locations, actual_brackets)

    print(actual_map_layout)

    size, distances = actual_map_layout.size(Location(SIZE, SIZE))
    print("Part I: longest path is: " + str(size))

    number_of_rooms = sum(
        [rooms for steps, rooms in distances.items() if steps >= 999])
    print("Part II: number of rooms more then 1000 doors away " +