


"""simple docstring"""







from __future__ import annotations

a__    :							Optional[int]            =					[
    [-1, 0],  # left
    [0, -1],  # down
    [1, 0],  # right
    [0, 1],  # up
]




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    [
					    [0 for col in range(len(grid[0]       )       )] for row in range(len(_snake_case       )       )
					]  # the reference grid
					__SCREAMING_SNAKE_CASE						       =    1
					__SCREAMING_SNAKE_CASE						       =    [
					    [0 for col in range(len(grid[0]       )       )] for row in range(len(_snake_case       )       )
					]  # the action grid

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

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

					while not found and not resign:
										if len(_snake_case       ) == 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()
															__SCREAMING_SNAKE_CASE						       =    cell.pop()
															__SCREAMING_SNAKE_CASE						       =    next_cell[2]
															__SCREAMING_SNAKE_CASE						       =    next_cell[3]
															__SCREAMING_SNAKE_CASE						       =    next_cell[1]

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

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


if __name__ == "__main__":
		a__    :							List[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],
		]

		a__    :							List[Any]            =					[0, 0]
		# all coordinates are given in format [y,x]
		a__    :							Optional[int]            =					[len(grid) - 1, len(grid[0]) - 1]
		a__    :							Any            =					1

		# the cost map which pushes the path closer to the goal
		a__    :							Dict            =					[[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])):
						a__    :							List[Any]            =					abs(i - goal[0]) + abs(j - goal[1])
						if grid[i][j] == 1:
								# added extra penalty in the heuristic map
								a__    :							Optional[int]            =					9_9

		a__    :							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])









"""simple docstring"""







from __future__ import annotations

import requests




def        UpperCAmelCase__	(lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    f"""https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty"""
					return requests.get(lowerCAmelCase_       ).json()




def        UpperCAmelCase__	(lowerCAmelCase_ = 10       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
					__SCREAMING_SNAKE_CASE						       =    requests.get(lowerCAmelCase_       ).json()[:max_stories]
					return [get_hackernews_story(lowerCAmelCase_       ) for story_id in story_ids]




def        UpperCAmelCase__	(lowerCAmelCase_ = 10       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    hackernews_top_stories(lowerCAmelCase_       )
					return "\n".join("* [{title}]({url})".format(**lowerCAmelCase_       ) for story in stories       )


if __name__ == "__main__":
		print(hackernews_top_stories_as_markdown())
