Last active
December 29, 2019 01:58
-
-
Save ryan-lam/781ebf1dfcfad22d039768d3188105d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qiskit | |
| qc = qiskit.QuantumCircuit(3,3) | |
| for i in range(3): | |
| qc.h(i) | |
| turns = 6 | |
| print("Welcome to Quantum PvP!. In this game, there are 3 qubits in a quantum circuit that start off in a superposition state. \ | |
| What you (player 1) are trying to do is to get the qubit to collapse into the \"0\" state. Your opponent (player 2) will \ | |
| trying to do the same, but they will be trying to get the qubit to collapse into the \"1\" state. \ | |
| You are both able to apply the [X], [Y], [Z], [Rx], [Ry], [Rz], [CNOT], [SWAP], and onto the circuit \ | |
| to manipulate the qubits. You each will have 3 opportunies to apply the gates before the game measures the qubits. Good luck!") | |
| def player(turns): | |
| if turns%2 == 0: | |
| return 1 | |
| else: | |
| return 2 | |
| while turns > 0: | |
| gate = input("It is player " + str(player(turns)) + "'s turn. Which gate would you like to apply? [X], [Y], [Z], [Rx], [Ry], [Rz], [CNOT] or the [SWAP] gate? Choose your section by typing the letters within the square brackets").replace(" ", "").lower() | |
| print(gate) | |
| if gate == "x": | |
| qubit = int(input("Which qubit would you like to apply the [X] gate to? Input \"1\", \"2\", or \"3\".").replace(" ","")) - 1 | |
| qc.x(qubit) | |
| print(qc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment