microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/pythontelem

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/marking_oracles/balanced/Solution.qs

23lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Math;
3
4 operation Oracle_Balanced(x : Qubit[], y : Qubit) : Unit is Adj + Ctl {
5 let N = Length(x);
6 let log = BitSizeI(N);
7 use inc = Qubit[log];
8 within {
9 for q in x {
10 Controlled Increment([q], inc);
11 }
12 } apply {
13 ApplyControlledOnInt(N / 2, X, inc, y);
14 }
15 }
16
17 operation Increment(register : Qubit[]) : Unit is Adj + Ctl {
18 if Length(register) > 1 {
19 Controlled Increment([register[0]], register[1 ...]);
20 }
21 X(register[0]);
22 }
23}
24