microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/deutsch_jozsa/implement_dj/Solution.qs
17lines · modecode
| 1 | namespace Kata { |
| 2 | open Microsoft.Quantum.Measurement; |
| 3 | |
| 4 | operation DeutschJozsaAlgorithm (N : Int, oracle : Qubit[] => Unit) : Bool { |
| 5 | mutable isConstant = true; |
| 6 | use x = Qubit[N]; |
| 7 | ApplyToEach(H, x); |
| 8 | oracle(x); |
| 9 | ApplyToEach(H, x); |
| 10 | for xi in x { |
| 11 | if MResetZ(xi) == One { |
| 12 | set isConstant = false; |
| 13 | } |
| 14 | } |
| 15 | return isConstant; |
| 16 | } |
| 17 | } |
| 18 | |