microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/second-api-refactor

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/deutsch_jozsa/implement_bv/Verification.qs

25lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Katas;
3 open Microsoft.Quantum.Math;
4
5 operation CheckSolution() : Bool {
6 for (n, oracle, expected, name) in [(2, qs => (), [0, 0], "f(x) = 0"),
7 (3, qs => (), [0, 0, 0], "f(x) = 0"),
8 (2, ApplyToEach(Z, _), [1, 1], "f(x) = parity of x"),
9 (3, ApplyToEach(Z, _), [1, 1, 1], "f(x) = parity of x"),
10 (2, qs => Z(qs[0]), [1, 0], "f(x) = most significant bit of x"),
11 (3, qs => Z(qs[2]), [0, 0, 1], "f(x) = least significant bit of x"),
12 (3, qs => Z(qs[1]), [0, 1, 0], "f(x) = middle bit of x")
13 ] {
14 let actual = Kata.BernsteinVaziraniAlgorithm(n, oracle);
15 if actual != expected {
16 Message("Incorrect.");
17 Message($"The bit string for {name} for {n} bits identified as {actual} but it is {expected}.");
18 return false;
19 }
20 }
21
22 Message("Correct!");
23 true
24 }
25}
26