





'''simple docstring'''






import numpy as np
import qiskit







def 					_a						(       _lowerCamelCase = 8    ,	_lowerCamelCase = None ) ->				str:



			"""simple docstring"""


			__snake_case					:      Any							      =     np.random.default_rng(seed=_lowerCamelCase )

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

			# Quantum Circuit to simulate BB84
			__snake_case					:      Dict							      =     qiskit.QuantumCircuit(_lowerCamelCase    ,	name="""BB84""" )

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

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

			bbaa_circ.barrier()
			bbaa_circ.measure_all()

			# Simulate the quantum circuit.
			__snake_case					:      int							      =     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.
			__snake_case					:      Any							      =     qiskit.execute(_lowerCamelCase    ,	_lowerCamelCase    ,	shots=1    ,	seed_simulator=_lowerCamelCase )
			# Returns the result of measurement.
			__snake_case					:      str							      =     job.result().get_counts(_lowerCamelCase ).most_frequent()

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

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


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

	testmod()









'''simple docstring'''






from __future__ import annotations

import math







def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase ) ->				int:



			"""simple docstring"""


			if depth < 0:
						raise ValueError("""Depth cannot be less than 0""" )

			if not scores:
						raise ValueError("""Scores cannot be empty""" )

			if depth == height:
						return scores[node_index]

			return (
			    max(
			        minimax(depth + 1    ,	node_index * 2    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase )    ,	minimax(depth + 1    ,	node_index * 2 + 1    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase )    ,	)
			    if is_max
			    else min(
			        minimax(depth + 1    ,	node_index * 2    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase )    ,	minimax(depth + 1    ,	node_index * 2 + 1    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase )    ,	)
			)







def 					_a						(       ) ->				None:



			"""simple docstring"""


			__snake_case					:      Union[str, Any]							      =     [90, 23, 6, 33, 21, 65, 123, 3_4423]
			__snake_case					:      Optional[int]							      =     math.log(len(_lowerCamelCase )    ,	2 )
			print(F'''Optimal value : {minimax(0    ,	0    ,	_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase )}''' )


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()


