microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/distinguishing_states/plus_minus/Verification.qs
30lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Katas; |
| 3 | |
| 4 | operation StatePrep_IsQubitPlus(q : Qubit, state : Int) : Unit is Adj { |
| 5 | if state == 1 { |
| 6 | // convert |0⟩ to |+⟩ |
| 7 | H(q); |
| 8 | } else { |
| 9 | // convert |0⟩ to |-⟩ |
| 10 | X(q); |
| 11 | H(q); |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | @EntryPoint() |
| 16 | operation CheckSolution() : Bool { |
| 17 | let isCorrect = DistinguishTwoStates_SingleQubit( |
| 18 | StatePrep_IsQubitPlus, |
| 19 | Kata.IsQubitPlus, |
| 20 | ["|-⟩", "|+⟩"], |
| 21 | false |
| 22 | ); |
| 23 | if isCorrect { |
| 24 | Message("Correct!"); |
| 25 | } else { |
| 26 | Message("Incorrect."); |
| 27 | } |
| 28 | isCorrect |
| 29 | } |
| 30 | } |
| 31 | |