code: import numpy as np
  import qiskit
  
  
  def 					__lowerCAmelCase			(  _A ,_A					):
  
  
  
  							"""simple docstring"""
  
  
  							_lowercase				=	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:
  														_lowercase				=	np.random.randint(1 ,2**num_qubits					)
  														# Next, format 'b' as a binary string of length 'n', padded with zeros:
  														_lowercase				=	format(_A ,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(_A					):
  																					if bit == "1":
  																												oracle_qc.x(_A					)
          # Do the controlled-NOT gates for each qubit, using the output qubit
          # as the target:
  														for index in range(_A					):
  																					oracle_qc.cx(_A ,_A					)
  														# Next, place the final X-gates
  														for index, bit in enumerate(_A					):
  																					if bit == "1":
  																												oracle_qc.x(_A					)
  
      # 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)
  														_lowercase				=	np.random.randint(2					)
  														if output == 1:
  																					oracle_qc.x(_A					)
  
  							_lowercase				=	oracle_qc.to_gate()
  							_lowercase				=	"""Oracle"""  # To show when we display the circuit
  							return oracle_gate
  
  
  def 					__lowerCAmelCase			(  _A ,_A					):
  
  
  
  							"""simple docstring"""
  
  
  							_lowercase				=	qiskit.QuantumCircuit(num_qubits + 1 ,_A					)
  							# Set up the output qubit:
  							dj_circuit.x(_A					)
  							dj_circuit.h(_A					)
  							# And set up the input register:
  							for qubit in range(_A					):
  														dj_circuit.h(_A					)
  							# Let's append the oracle gate to our circuit:
  							dj_circuit.append(_A ,range(num_qubits + 1					)					)
  							# Finally, perform the H-gates again and measure:
  							for qubit in range(_A					):
  														dj_circuit.h(_A					)
  
  							for i in range(_A					):
  														dj_circuit.measure(_A ,_A					)
  
  							return dj_circuit
  
  
  def 					__lowerCAmelCase			(  _A ,_A					):
  
  
  
  							"""simple docstring"""
  
  
  							_lowercase				=	qiskit.Aer.get_backend("""aer_simulator"""					)
  
  							_lowercase				=	dj_oracle(_A ,_A					)
  							_lowercase				=	dj_algorithm(_A ,_A					)
  
  							# Execute the circuit on the simulator
  							_lowercase				=	qiskit.execute(_A ,_A ,shots=1_000					)
  
  							# Return the histogram data of the results of the experiment.
  							return job.result().get_counts(_A					)
  
  
  if __name__ == "__main__":
  				print(F'''Deutsch Jozsa - Constant Oracle: {deutsch_jozsa('constant', 3)}''')
  				print(F'''Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa('balanced', 3)}''')
  
  
  
style_context: import math
  from timeit import timeit
  
  
  def 					__lowerCAmelCase			(  _A					):
  
  
  
  							"""simple docstring"""
  
  
  							_lowercase				=	0
  							_lowercase				=	abs(_A					)
  							while True:
  														_lowercase				=	n // 10
  														digits += 1
  														if n == 0:
  																					break
  							return digits
  
  
  def 					__lowerCAmelCase			(  _A					):
  
  
  
  							"""simple docstring"""
  
  
  							return 1 if n == 0 else math.floor(math.log(abs(_A					) ,10					) + 1					)
  
  
  def 					__lowerCAmelCase			(  _A					):
  
  
  
  							"""simple docstring"""
  
  
  							return len(str(abs(_A					)					)					)
  
  
  def 					__lowerCAmelCase			(  ):
  
  
  
  							"""simple docstring"""
  
  
  							from collections.abc import Callable
  
  							def benchmark_a_function(_A ,_A					) -> None:
  														_lowercase				=	f'''{func.__name__}({value})'''
  														_lowercase				=	timeit(f'''__main__.{call}''' ,setup="""import __main__"""					)
  														print(f'''{call}: {func(_A					)} -- {timing} seconds'''					)
  
  							for value in (262_144, 1_125_899_906_842_624, 1_267_650_600_228_229_401_496_703_205_376):
  														for func in (num_digits, num_digits_fast, num_digits_faster):
  																					benchmark_a_function(_A ,_A					)
  														print()
  
  
  if __name__ == "__main__":
  				import doctest
  
  				doctest.testmod()
  				benchmark()
  
  
  