






from __future__ import annotations

from statistics import mean






def   UpperCamelCase  (       snake_case__     :   list[int]	,snake_case__     :   list[int]	,snake_case__     :   int  ):




     '''simple docstring'''






     __snake_case			:Any          =						[0] * no_of_processes
     __snake_case			:Optional[int]          =						[0] * no_of_processes

     # Initialize remaining_time to waiting_time.

     for i in range(snake_case__  ):
          __snake_case			:Union[str, Any]          =						burst_time[i]
     __snake_case			:list[int]          =						[]

     __snake_case			:Union[str, Any]          =						0
     __snake_case			:str          =						0

     # When processes are not completed,
     # A process whose arrival time has passed \
     # and has remaining execution time is put into the ready_process.
     # The shortest process in the ready_process, target_process is executed.

     while completed != no_of_processes:
          __snake_case			:List[str]          =						[]
          __snake_case			:Optional[Any]          =						-1

          for i in range(snake_case__  ):
               if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
                    ready_process.append(snake_case__  )

          if len(snake_case__  ) > 0:
               __snake_case			:Any          =						ready_process[0]
               for i in ready_process:
                    if remaining_time[i] < remaining_time[target_process]:
                         __snake_case			:List[str]          =						i
               total_time += burst_time[target_process]
               completed += 1
               __snake_case			:Optional[Any]          =						0
               __snake_case			:Dict          =						(
                   total_time - arrival_time[target_process] - burst_time[target_process]
               )
          else:
               total_time += 1

     return waiting_time






def   UpperCamelCase  (       snake_case__     :   list[int]	,snake_case__     :   int	,snake_case__     :   list[int]  ):




     '''simple docstring'''






     __snake_case			:List[str]          =						[0] * no_of_processes
     for i in range(snake_case__  ):
          __snake_case			:Optional[Any]          =						burst_time[i] + waiting_time[i]
     return turn_around_time


if __name__ == "__main__":
     print("""[TEST CASE 01]""")

     lowerCamelCase__							=     4
     lowerCamelCase__							=     [2, 5, 3, 7]
     lowerCamelCase__							=     [0, 0, 0, 0]
     lowerCamelCase__							=     calculate_waitingtime(arrival_time, burst_time, no_of_processes)
     lowerCamelCase__							=     calculate_turnaroundtime(
         burst_time, no_of_processes, waiting_time
     )

     # Printing the Result
     print("""PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time""")
     for i, process_id in enumerate(list(range(1, 5))):
          print(
              f'''{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t'''
              f'''{waiting_time[i]}\t\t\t\t{turn_around_time[i]}'''
          )
     print(f'''\nAverage waiting time = {mean(waiting_time):.5f}''')
     print(f'''Average turnaround time = {mean(turn_around_time):.5f}''')










import numpy as np
import qiskit






def   UpperCamelCase  (       snake_case__     :   int = 8	,snake_case__     :   int | None = None  ):




     '''simple docstring'''






     __snake_case			:Tuple          =						np.random.default_rng(seed=snake_case__  )

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

     # Quantum Circuit to simulate BB84
     __snake_case			:Optional[int]          =						qiskit.QuantumCircuit(snake_case__	,name="""BB84"""  )

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

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

     bbaa_circ.barrier()
     bbaa_circ.measure_all()

     # Simulate the quantum circuit.
     __snake_case			:Optional[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			:List[Any]          =						qiskit.execute(snake_case__	,snake_case__	,shots=1	,seed_simulator=snake_case__  )
     # Returns the result of measurement.
     __snake_case			:Tuple          =						job.result().get_counts(snake_case__  ).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(
                 snake_case__	,snake_case__	,snake_case__  )
             if alice_basis_bit == bob_basis_bit
         ]  )

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


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

     testmod()


