microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/marking_oracles/bit_sum_div_3/Solution.qs
19lines · modecode
| 1 | namespace Kata { |
| 2 | operation Oracle_BitSumDivisibleBy3 (x : Qubit[], y : Qubit) : Unit is Adj + Ctl { |
| 3 | use counter = Qubit[2]; |
| 4 | within { |
| 5 | for q in x { |
| 6 | Controlled IncrementMod3([q], counter); |
| 7 | } |
| 8 | } apply { |
| 9 | ApplyControlledOnInt(0, X, counter, y); |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | operation IncrementMod3 (counterRegister : Qubit[]) : Unit is Adj + Ctl { |
| 14 | let sum = counterRegister[0]; |
| 15 | let carry = counterRegister[1]; |
| 16 | ApplyControlledOnInt(0, X, [carry], sum); |
| 17 | ApplyControlledOnInt(0, X, [sum], carry); |
| 18 | } |
| 19 | } |
| 20 | |