




"""simple docstring"""




def 					A				(				_SCREAMING_SNAKE_CASE   )     ->			bool:
       # must be
       lowerCamelCase       :				int      			= [list(_SCREAMING_SNAKE_CASE   ) for row in matrix]
       if matrix and isinstance(_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   ):
              if isinstance(matrix[0]			,_SCREAMING_SNAKE_CASE   ):
                     lowerCamelCase       :				Tuple      			= 0
                     for row in matrix:
                            if prev_len == 0:
                                   lowerCamelCase       :				Dict      			= len(_SCREAMING_SNAKE_CASE   )
                                   lowerCamelCase       :				Dict      			= True
                            else:
                                   lowerCamelCase       :				Optional[Any]      			= prev_len == len(_SCREAMING_SNAKE_CASE   )
              else:
                     lowerCamelCase       :				Dict      			= True
       else:
              lowerCamelCase       :				Tuple      			= False

       return result

def 					A				(				_SCREAMING_SNAKE_CASE   )     ->			None:
       if check_matrix(_SCREAMING_SNAKE_CASE   ) and len(_SCREAMING_SNAKE_CASE   ) > 0:
              lowerCamelCase       :				Dict      			= [list(_SCREAMING_SNAKE_CASE   ) for row in a]
              lowerCamelCase       :				str      			= len(_SCREAMING_SNAKE_CASE   )
              if isinstance(a[0]			,_SCREAMING_SNAKE_CASE   ):
                     lowerCamelCase       :				List[str]      			= len(a[0]   )
              else:
                     for dat in a:
                            print(_SCREAMING_SNAKE_CASE   )
                     return

              # horizotal printing increasing
              for i in range(0			,_SCREAMING_SNAKE_CASE   ):
                     print(a[0][i]   )
              # vertical printing down
              for i in range(1			,_SCREAMING_SNAKE_CASE   ):
                     print(a[i][mat_col - 1]   )
              # horizotal printing decreasing
              if mat_row > 1:
                     for i in range(mat_col - 2			,-1			,-1   ):
                            print(a[mat_row - 1][i]   )
        # vertical printing up
              for i in range(mat_row - 2			,0			,-1   ):
                     print(a[i][0]   )
              lowerCamelCase       :				Union[str, Any]      			= [row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
              if len(_SCREAMING_SNAKE_CASE   ) > 0:
                     spiral_print_clockwise(_SCREAMING_SNAKE_CASE   )
              else:
                     return
       else:
              print("Not a valid matrix"   )
              return

def 					A				(				_SCREAMING_SNAKE_CASE   )     ->			list[int]:
       if matrix:
              return list(matrix.pop(0   )   ) + spiral_traversal(list(zip(*_SCREAMING_SNAKE_CASE   )   )[::-1]   )
       else:
              return []


# driver code
if __name__ == "__main__":
       import doctest

       doctest.testmod()

       SCREAMING_SNAKE_CASE__	:				Tuple  =       [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
       spiral_print_clockwise(a)












import numpy as np
import qiskit

def 					A				(				_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   )     ->			qiskit.QuantumCircuit:
       lowerCamelCase       :				Optional[int]      			= 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:
              lowerCamelCase       :				Optional[int]      			= np.random.randint(1			,2**num_qubits   )
              # Next, format 'b' as a binary string of length 'n', padded with zeros:
              lowerCamelCase       :				str      			= format(_SCREAMING_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(_SCREAMING_SNAKE_CASE   ):
                     if bit == "1":
                            oracle_qc.x(_SCREAMING_SNAKE_CASE   )
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
              for index in range(_SCREAMING_SNAKE_CASE   ):
                     oracle_qc.cx(_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   )
              # Next, place the final X-gates
              for index, bit in enumerate(_SCREAMING_SNAKE_CASE   ):
                     if bit == "1":
                            oracle_qc.x(_SCREAMING_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)
              lowerCamelCase       :				str      			= np.random.randint(2   )
              if output == 1:
                     oracle_qc.x(_SCREAMING_SNAKE_CASE   )

       lowerCamelCase       :				int      			= oracle_qc.to_gate()
       lowerCamelCase       :				Tuple      			= "Oracle"  # To show when we display the circuit
       return oracle_gate

def 					A				(				_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   )     ->			qiskit.QuantumCircuit:
       lowerCamelCase       :				Union[str, Any]      			= qiskit.QuantumCircuit(num_qubits + 1			,_SCREAMING_SNAKE_CASE   )
       # Set up the output qubit:
       dj_circuit.x(_SCREAMING_SNAKE_CASE   )
       dj_circuit.h(_SCREAMING_SNAKE_CASE   )
       # And set up the input register:
       for qubit in range(_SCREAMING_SNAKE_CASE   ):
              dj_circuit.h(_SCREAMING_SNAKE_CASE   )
       # Let's append the oracle gate to our circuit:
       dj_circuit.append(_SCREAMING_SNAKE_CASE			,range(num_qubits + 1   )   )
       # Finally, perform the H-gates again and measure:
       for qubit in range(_SCREAMING_SNAKE_CASE   ):
              dj_circuit.h(_SCREAMING_SNAKE_CASE   )

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

       return dj_circuit

def 					A				(				_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   )     ->			qiskit.result.counts.Counts:
       lowerCamelCase       :				Tuple      			= qiskit.Aer.get_backend("aer_simulator"   )

       lowerCamelCase       :				Tuple      			= dj_oracle(_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   )
       lowerCamelCase       :				List[Any]      			= dj_algorithm(_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE   )

       # Execute the circuit on the simulator
       lowerCamelCase       :				List[Any]      			= qiskit.execute(_SCREAMING_SNAKE_CASE			,_SCREAMING_SNAKE_CASE			,shots=1000   )

       # Return the histogram data of the results of the experiment.
       return job.result().get_counts(_SCREAMING_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)}''')






