microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/multi_qubit_gates/arbitrary_controls/Verification.qs

34lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Arrays;
3 open Microsoft.Quantum.Convert;
4 open Microsoft.Quantum.Diagnostics;
5 open Microsoft.Quantum.Katas;
6
7 operation MultiControls(controls : Qubit[], target : Qubit, controlBits : Bool[]) : Unit is Adj + Ctl {
8 within {
9 for index in 0 .. Length(controls) - 1 {
10 if controlBits[index] == false {
11 X(controls[index]);
12 }
13 }
14 } apply {
15 Controlled X(controls,target);
16 }
17 }
18
19 operation CheckSolution() : Bool {
20 for i in 0 .. (2 ^ 4) - 1 {
21 let bits = IntAsBoolArray(i, 4);
22 let solution = register => Kata.MultiControls(Most(register), Tail(register), bits);
23 let reference = register => MultiControls(Most(register), Tail(register), bits);
24 if not CheckOperationsEquivalence(solution, reference, 5) {
25 Message("Incorrect.");
26 Message($"The test case for controlBits = {bits} did not pass.");
27 return false;
28 }
29 }
30
31 Message("Correct!");
32 true
33 }
34}