



from __future__ import annotations

__snake_case						:Optional[Any]						=					[
    [-1, 0],  # left
    [0, -1],  # down
    [1, 0],  # right
    [0, 1],  # up
]





def 					__snake_case     (      _UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase       ,			):
    __a							=    [
        [0 for col in range(len(grid[0]    )    )] for row in range(len(_lowercase    )    )
    ]  # the reference grid
    __a							=    1
    __a							=    [
        [0 for col in range(len(grid[0]    )    )] for row in range(len(_lowercase    )    )
    ]  # the action grid

    __a							=    init[0]
    __a							=    init[1]
    __a							=    0
    __a							=    g + heuristic[x][y]  # cost from starting cell to destination cell
    __a							=    [[f, g, x, y]]

    __a							=    False  # flag that is set when search is complete
    __a							=    False  # flag set if we can't find expand

    while not found and not resign:
        if len(_lowercase    ) == 0:
            raise ValueError('''Algorithm is unable to find solution'''    )
        else:  # to choose the least costliest action so as to move closer to the goal
            cell.sort()
            cell.reverse()
            __a							=    cell.pop()
            __a							=    next_cell[2]
            __a							=    next_cell[3]
            __a							=    next_cell[1]

            if x == goal[0] and y == goal[1]:
                __a							=    True
            else:
                for i in range(len(_lowercase    )    ):  # to try out different valid actions
                    __a							=    x + DIRECTIONS[i][0]
                    __a							=    y + DIRECTIONS[i][1]
                    if xa >= 0 and xa < len(_lowercase    ) and ya >= 0 and ya < len(grid[0]    ):
                        if closed[xa][ya] == 0 and grid[xa][ya] == 0:
                            __a							=    g + cost
                            __a							=    ga + heuristic[xa][ya]
                            cell.append([fa, ga, xa, ya]    )
                            __a							=    1
                            __a							=    i
    __a							=    []
    __a							=    goal[0]
    __a							=    goal[1]
    invpath.append([x, y]    )  # we get the reverse path from here
    while x != init[0] or y != init[1]:
        __a							=    x - DIRECTIONS[action[x][y]][0]
        __a							=    y - DIRECTIONS[action[x][y]][1]
        __a							=    xa
        __a							=    ya
        invpath.append([x, y]    )

    __a							=    []
    for i in range(len(_lowercase    )    ):
        path.append(invpath[len(_lowercase    ) - 1 - i]    )
    return path, action


if __name__ == "__main__":
 __snake_case						:str						=					[
     [0, 1, 0, 0, 0, 0],
     [0, 1, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
     [0, 1, 0, 0, 0, 0],
     [0, 1, 0, 0, 1, 0],
     [0, 0, 0, 0, 1, 0],
 ]

 __snake_case						:int						=					[0, 0]
 # all coordinates are given in format [y,x]
 __snake_case						:Dict						=					[len(grid) - 1, len(grid[0]) - 1]
 __snake_case						:int						=					1

 # the cost map which pushes the path closer to the goal
 __snake_case						:Optional[int]						=					[[0 for row in range(len(grid[0]))] for col in range(len(grid))]
 for i in range(len(grid)):
  for j in range(len(grid[0])):
   __snake_case						:Optional[Any]						=					abs(i - goal[0]) + abs(j - goal[1])
   if grid[i][j] == 1:
    # added extra penalty in the heuristic map
    __snake_case						:Optional[Any]						=					99

 __snake_case						:Optional[int]						=					search(grid, init, goal, cost, heuristic)

 print('''ACTION MAP''')
 for i in range(len(action)):
  print(action[i])

 for i in range(len(path)):
  print(path[i])








def 					__snake_case     (      _UpperCAmelCase       ,			_UpperCAmelCase    ):
    return base * power(_UpperCAmelCase       ,			(exponent - 1)    ) if exponent else 1


if __name__ == "__main__":
 print('''Raise base to the power of exponent using recursion...''')
 __snake_case						:List[Any]						=					int(input('''Enter the base: ''').strip())
 __snake_case						:Dict						=					int(input('''Enter the exponent: ''').strip())
 __snake_case						:int						=					power(base, abs(exponent))
 if exponent < 0:  # power() does not properly deal w/ negative exponents
  __snake_case						:Optional[Any]						=					1 / result
 print(f'{base} to the power of {exponent} is {result}')





