

"""simple docstring"""




import numpy as np
import qiskit

def 		A    (       snake_case__						,			snake_case__      ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__									= qiskit.QuantumCircuit(num_qubits + 1      )

			# First, let's deal with the case in which oracle is balanced
			if case == "balanced":
						# First generate a random number that tells us which CNOTs to
						# wrap in X-gates:
						SCREAMING_SNAKE_CASE__									= np.random.randint(1						,			2**num_qubits      )
						# Next, format 'b' as a binary string of length 'n', padded with zeros:
						SCREAMING_SNAKE_CASE__									= format(snake_case__						,			f"""0{num_qubits}b"""      )
						# Next, we place the first X-gates. Each digit in our binary string
						# corresponds to a qubit, if the digit is 0, we do nothing, if it's 1
						# we apply an X-gate to that qubit:
						for index, bit in enumerate(snake_case__      ):
									if bit == "1":
												oracle_qc.x(snake_case__      )
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
						for index in range(snake_case__      ):
									oracle_qc.cx(snake_case__						,			snake_case__      )
						# Next, place the final X-gates
						for index, bit in enumerate(snake_case__      ):
									if bit == "1":
												oracle_qc.x(snake_case__      )

    # Case in which oracle is constant
			if case == "constant":
						# First decide what the fixed output of the oracle will be
						# (either always 0 or always 1)
						SCREAMING_SNAKE_CASE__									= np.random.randint(2      )
						if output == 1:
									oracle_qc.x(snake_case__      )

			SCREAMING_SNAKE_CASE__									= oracle_qc.to_gate()
			SCREAMING_SNAKE_CASE__									= """Oracle"""  # To show when we display the circuit
			return oracle_gate

def 		A    (       snake_case__						,			snake_case__      ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__									= qiskit.QuantumCircuit(num_qubits + 1						,			snake_case__      )
			# Set up the output qubit:
			dj_circuit.x(snake_case__      )
			dj_circuit.h(snake_case__      )
			# And set up the input register:
			for qubit in range(snake_case__      ):
						dj_circuit.h(snake_case__      )
			# Let's append the oracle gate to our circuit:
			dj_circuit.append(snake_case__						,			range(num_qubits + 1      )      )
			# Finally, perform the H-gates again and measure:
			for qubit in range(snake_case__      ):
						dj_circuit.h(snake_case__      )

			for i in range(snake_case__      ):
						dj_circuit.measure(snake_case__						,			snake_case__      )

			return dj_circuit

def 		A    (       snake_case__						,			snake_case__      ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__									= qiskit.Aer.get_backend("""aer_simulator"""      )

			SCREAMING_SNAKE_CASE__									= dj_oracle(snake_case__						,			snake_case__      )
			SCREAMING_SNAKE_CASE__									= dj_algorithm(snake_case__						,			snake_case__      )

			# Execute the circuit on the simulator
			SCREAMING_SNAKE_CASE__									= qiskit.execute(snake_case__						,			snake_case__						,			shots=10_00      )

			# Return the histogram data of the results of the experiment.
			return job.result().get_counts(snake_case__      )


if __name__ == "__main__":
						print(F'Deutsch Jozsa - Constant Oracle: {deutsch_jozsa("constant", 3)}')
						print(F'Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa("balanced", 3)}')





"""simple docstring"""




class 				lowerCamelCase  :

			def __init__(   self			:  Dict    )				->      None:
						SCREAMING_SNAKE_CASE__									= [0, 1]





			def    SCREAMING_SNAKE_CASE			(   self			:  Optional[int]      ,			__UpperCAmelCase			:  int    )				->      list:
						if (difference := index - (len(self.sequence    ) - 2)) >= 1:
									for _ in range(__UpperCAmelCase    ):
												self.sequence.append(self.sequence[-1] + self.sequence[-2]    )
						return self.sequence[:index]

def 		A    (       ):




			'''simple docstring'''


			print(
			    """Fibonacci Series Using Dynamic Programming\n"""						,			"""Enter the index of the Fibonacci number you want to calculate """						,			"""in the prompt below. (To exit enter exit or Ctrl-C)\n"""						,			sep=""""""						,			)
			SCREAMING_SNAKE_CASE__									= Fibonacci()

			while True:
						SCREAMING_SNAKE_CASE__									= input(""">> """      )
						if prompt in {"exit", "quit"}:
									break

						try:
									SCREAMING_SNAKE_CASE__									= int(snake_case__      )
						except ValueError:
									print("""Enter a number or 'exit'"""      )
									continue

						print(fibonacci.get(snake_case__      )      )


if __name__ == "__main__":
						main()


