microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/marking_oracles/contains_substring/Solution.qs
19lines · modecode
| 1 | namespace Kata { |
| 2 | operation Oracle_ContainsSubstring (x : Qubit[], y : Qubit, r : Bool[]) : Unit is Adj + Ctl { |
| 3 | let N = Length(x); |
| 4 | let K = Length(r); |
| 5 | use aux = Qubit[N - K + 1]; |
| 6 | within { |
| 7 | for P in 0 .. N - K { |
| 8 | Oracle_ContainsSubstringAtPosition(x, aux[P], r, P); |
| 9 | } |
| 10 | } apply { |
| 11 | ApplyControlledOnInt(0, X, aux, y); |
| 12 | X(y); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | operation Oracle_ContainsSubstringAtPosition (x : Qubit[], y : Qubit, r : Bool[], p : Int) : Unit is Adj + Ctl { |
| 17 | ApplyControlledOnBitString(r, X, x[p .. p + Length(r) - 1], y); |
| 18 | } |
| 19 | } |
| 20 | |