microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dmitryv/select-updated

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/oracles/bit_pattern_oracle/verification.qs

29lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Convert;
3
4 operation ArbitraryBitPattern_Oracle_Reference(x : Qubit[], y : Qubit, pattern : Bool[]) : Unit is Adj + Ctl {
5 ApplyControlledOnBitString(pattern, X, x, y);
6 }
7
8 // ------------------------------------------------------
9 @EntryPoint()
10 operation CheckSolution() : Bool {
11 for N in 1..4 {
12 for k in 0..((2^N)-1) {
13 let pattern = IntAsBoolArray(k, N);
14
15 let isCorrect = CheckTwoOraclesAreEqual(
16 N..N,
17 Kata.ArbitraryBitPattern_Oracle(_, _, pattern),
18 ArbitraryBitPattern_Oracle_Reference(_, _, pattern));
19 if not isCorrect {
20 Message($"Failed on pattern {pattern}.");
21 return false;
22 }
23 }
24 }
25 Message("All tests passed.");
26 true
27 }
28
29}
30