






_a    :   List[Any]        =			{
    """A""": ["""B""", """C""", """E"""],
    """B""": ["""A""", """D""", """E"""],
    """C""": ["""A""", """F""", """G"""],
    """D""": ["""B"""],
    """E""": ["""A""", """B""", """D"""],
    """F""": ["""C"""],
    """G""": ["""C"""],
}


def 				snake_case__							(							UpperCAmelCase							:  dict    ,			UpperCAmelCase							:  Optional[int]    ,			UpperCAmelCase							:  Tuple       ):
    lowerCAmelCase__   :int      							=				set()
    # keep track of all the paths to be checked
    lowerCAmelCase__   :Dict      							=				[[start]]

    # return path if start is goal
    if start == goal:
        return [start]

    # keeps looping until all possible paths have been checked
    while queue:
        # pop the first path from the queue
        lowerCAmelCase__   :Optional[int]      							=				queue.pop(0       )
        # get the last node from the path
        lowerCAmelCase__   :int      							=				path[-1]
        if node not in explored:
            lowerCAmelCase__   :str      							=				graph[node]
            # go through all neighbour nodes, construct a new path and
            # push it into the queue
            for neighbour in neighbours:
                lowerCAmelCase__   :Dict      							=				list(UpperCAmelCase       )
                new_path.append(UpperCAmelCase       )
                queue.append(UpperCAmelCase       )
                # return path if neighbour is goal
                if neighbour == goal:
                    return new_path

            # mark node as explored
            explored.add(UpperCAmelCase       )

    # in case there's no path between the 2 nodes
    return []


def 				snake_case__							(							UpperCAmelCase							:  dict    ,			UpperCAmelCase							:  List[Any]    ,			UpperCAmelCase							:  Union[str, Any]       ):
    if not graph or start not in graph or target not in graph:
        return -1
    if start == target:
        return 0
    lowerCAmelCase__   :Optional[int]      							=				[start]
    lowerCAmelCase__   :Tuple      							=				set(UpperCAmelCase       )
    # Keep tab on distances from `start` node.
    lowerCAmelCase__   :Union[str, Any]      							=				{start: 0, target: -1}
    while queue:
        lowerCAmelCase__   :Tuple      							=				queue.pop(0       )
        if node == target:
            lowerCAmelCase__   :Any      							=				(
                dist[node] if dist[target] == -1 else min(dist[target]    ,			dist[node]       )
            )
        for adjacent in graph[node]:
            if adjacent not in visited:
                visited.add(UpperCAmelCase       )
                queue.append(UpperCAmelCase       )
                lowerCAmelCase__   :str      							=				dist[node] + 1
    return dist[target]


if __name__ == "__main__":
 print(bfs_shortest_path(demo_graph, """G""", """D"""))  # returns ['G', 'C', 'A', 'B', 'D']
 print(bfs_shortest_path_distance(demo_graph, """G""", """D"""))  # returns 4











from collections.abc import Callable
from math import pi, sqrt
from random import uniform
from statistics import mean


def 				snake_case__							(							UpperCAmelCase							:  int       ):

    # A local function to see if a dot lands in the circle.
    def is_in_circle(UpperCAmelCase							:  float    ,			UpperCAmelCase							:  float       ) -> bool:
        lowerCAmelCase__   :Optional[int]      							=				sqrt((x**2) + (y**2)       )
        # Our circle has a radius of 1, so a distance
        # greater than 1 would land outside the circle.
        return distance_from_centre <= 1

    # The proportion of guesses that landed in the circle
    lowerCAmelCase__   :Union[str, Any]      							=				mean(
        int(is_in_circle(uniform(-1.0    ,			1.0       )    ,			uniform(-1.0    ,			1.0       )       )       )
        for _ in range(UpperCAmelCase       )       )
    # The ratio of the area for circle to square is pi/4.
    lowerCAmelCase__   :List[Any]      							=				proportion * 4
    print(F'''The estimated value of pi is {pi_estimate}'''       )
    print(F'''The numpy value of pi is {pi}'''       )
    print(F'''The total error is {abs(pi - pi_estimate       )}'''       )


def 				snake_case__							(							UpperCAmelCase							:  int    ,			UpperCAmelCase							:  Callable[[float], float]    ,			UpperCAmelCase							:  float = 0.0    ,			UpperCAmelCase							:  float = 1.0    ,			):
    return mean(
        function_to_integrate(uniform(UpperCAmelCase    ,			UpperCAmelCase       )       ) for _ in range(UpperCAmelCase       )       ) * (max_value - min_value)


def 				snake_case__							(							UpperCAmelCase							:  int    ,			UpperCAmelCase							:  float = 0.0    ,			UpperCAmelCase							:  float = 1.0       ):

    def identity_function(UpperCAmelCase							:  float       ) -> float:
        return x

    lowerCAmelCase__   :List[str]      							=				area_under_curve_estimator(
        UpperCAmelCase    ,			UpperCAmelCase    ,			UpperCAmelCase    ,			UpperCAmelCase       )
    lowerCAmelCase__   :Tuple      							=				(max_value * max_value - min_value * min_value) / 2

    print("******************"       )
    print(F'''Estimating area under y=x where x varies from {min_value} to {max_value}'''       )
    print(F'''Estimated value is {estimated_value}'''       )
    print(F'''Expected value is {expected_value}'''       )
    print(F'''Total error is {abs(estimated_value - expected_value       )}'''       )
    print("******************"       )


def 				snake_case__							(							UpperCAmelCase							:  int       ):

    def function_to_integrate(UpperCAmelCase							:  float       ) -> float:
        return sqrt(4.0 - x * x       )

    lowerCAmelCase__   :int      							=				area_under_curve_estimator(
        UpperCAmelCase    ,			UpperCAmelCase    ,			0.0    ,			2.0       )

    print("******************"       )
    print("Estimating pi using area_under_curve_estimator"       )
    print(F'''Estimated value is {estimated_value}'''       )
    print(F'''Expected value is {pi}'''       )
    print(F'''Total error is {abs(estimated_value - pi       )}'''       )
    print("******************"       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()



