'''simple docstring'''







from __future__ import annotations

UpperCamelCase_      	=	[
    [-1, 0],  # left
    [0, -1],  # down
    [1, 0],  # right
    [0, 1],  # up
]


def    lowerCamelCase       (			UpperCAmelCase__				:  list[list[int]]				,						UpperCAmelCase__				:  list[int]				,						UpperCAmelCase__				:  list[int]				,						UpperCAmelCase__				:  int				,						UpperCAmelCase__				:  list[list[int]]				,						)			->	tuple[list[list[int]], list[list[int]]]:


							'''simple docstring'''






							SCREAMING_SNAKE_CASE__     :str						    = [
							    [0 for col in range(len(grid[0]		)		)] for row in range(len(UpperCAmelCase__		)		)
							]  # the reference grid
							SCREAMING_SNAKE_CASE__     :Any						    = 1
							SCREAMING_SNAKE_CASE__     :Dict						    = [
							    [0 for col in range(len(grid[0]		)		)] for row in range(len(UpperCAmelCase__		)		)
							]  # the action grid

							SCREAMING_SNAKE_CASE__     :int						    = init[0]
							SCREAMING_SNAKE_CASE__     :Optional[Any]						    = init[1]
							SCREAMING_SNAKE_CASE__     :List[str]						    = 0
							SCREAMING_SNAKE_CASE__     :List[Any]						    = g + heuristic[x][y]  # cost from starting cell to destination cell
							SCREAMING_SNAKE_CASE__     :List[Any]						    = [[f, g, x, y]]

							SCREAMING_SNAKE_CASE__     :Any						    = False  # flag that is set when search is complete
							SCREAMING_SNAKE_CASE__     :str						    = False  # flag set if we can't find expand

							while not found and not resign:
														if len(UpperCAmelCase__		) == 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__     :List[Any]						    = cell.pop()
																					SCREAMING_SNAKE_CASE__     :Optional[int]						    = next_cell[2]
																					SCREAMING_SNAKE_CASE__     :Any						    = next_cell[3]
																					SCREAMING_SNAKE_CASE__     :Dict						    = next_cell[1]

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

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


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

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

		# the cost map which pushes the path closer to the goal
		UpperCamelCase_      	=	[[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])):
						UpperCamelCase_      	=	abs(i - goal[0]) + abs(j - goal[1])
						if grid[i][j] == 1:
								# added extra penalty in the heuristic map
								UpperCamelCase_      	=	99

		UpperCamelCase_	,			UpperCamelCase_      	=	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'''







import numpy as np
import qiskit


def    lowerCamelCase       (			UpperCAmelCase__				:  int = 8				,						UpperCAmelCase__				:  int | None = None		)			->	str:


							'''simple docstring'''






							SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = np.random.default_rng(seed=UpperCAmelCase__		)

							# Roughly 25% of the qubits will contribute to the key.
							# So we take more than we need.
							SCREAMING_SNAKE_CASE__     :Optional[int]						    = 6 * key_len
							# Measurement basis for Alice's qubits.
							SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = rng.integers(2				,						size=UpperCAmelCase__		)
							# The set of states Alice will prepare.
							SCREAMING_SNAKE_CASE__     :List[Any]						    = rng.integers(2				,						size=UpperCAmelCase__		)
							# Measurement basis for Bob's qubits.
							SCREAMING_SNAKE_CASE__     :str						    = rng.integers(2				,						size=UpperCAmelCase__		)

							# Quantum Circuit to simulate BB84
							SCREAMING_SNAKE_CASE__     :int						    = qiskit.QuantumCircuit(UpperCAmelCase__				,						name='BB84'		)

							# Alice prepares her qubits according to rules above.
							for index, _ in enumerate(UpperCAmelCase__		):
														if alice_state[index] == 1:
																					bbaa_circ.x(UpperCAmelCase__		)
														if alice_basis[index] == 1:
																					bbaa_circ.h(UpperCAmelCase__		)
							bbaa_circ.barrier()

							# Bob measures the received qubits according to rules above.
							for index, _ in enumerate(UpperCAmelCase__		):
														if bob_basis[index] == 1:
																					bbaa_circ.h(UpperCAmelCase__		)

							bbaa_circ.barrier()
							bbaa_circ.measure_all()

							# Simulate the quantum circuit.
							SCREAMING_SNAKE_CASE__     :str						    = qiskit.Aer.get_backend('aer_simulator'		)
							# We only need to run one shot because the key is unique.
							# Multiple shots will produce the same key.
							SCREAMING_SNAKE_CASE__     :int						    = qiskit.execute(UpperCAmelCase__				,						UpperCAmelCase__				,						shots=1				,						seed_simulator=UpperCAmelCase__		)
							# Returns the result of measurement.
							SCREAMING_SNAKE_CASE__     :List[Any]						    = job.result().get_counts(UpperCAmelCase__		).most_frequent()

							# Extracting the generated key from the simulation results.
							# Only keep measurement results where Alice and Bob chose the same basis.
							SCREAMING_SNAKE_CASE__     :Any						    = ''.join(
							    [
							        result_bit
							        for alice_basis_bit, bob_basis_bit, result_bit in zip(
							            UpperCAmelCase__				,						UpperCAmelCase__				,						UpperCAmelCase__		)
							        if alice_basis_bit == bob_basis_bit
							    ]		)

							# Get final key. Pad with 0 if too short, otherwise truncate.
							SCREAMING_SNAKE_CASE__     :Optional[Any]						    = gen_key[:key_len] if len(UpperCAmelCase__		) >= key_len else gen_key.ljust(UpperCAmelCase__				,						'0'		)
							return key


if __name__ == "__main__":
		print(f"The generated key is : {bbaa(8, seed=0)}")
		from doctest import testmod

		testmod()






