microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
swernli/eval-optimization

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

katas/content/marking_oracles/bit_sum_div_3/Solution.qs

19lines · modecode

1namespace 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