microsoft/qdk

Public

mirrored fromhttps://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/oracles/bit_pattern_challenge/Verification.qs

37lines · modecode

1namespace Kata.Verification {
2 open Microsoft.Quantum.Convert;
3 open Microsoft.Quantum.Arrays;
4
5 operation ArbitraryBitPattern_Oracle_Challenge_Reference(x : Qubit[], pattern : Bool[]) : Unit is Adj + Ctl {
6 within {
7 for i in IndexRange(x) {
8 if not pattern[i] {
9 X(x[i]);
10 }
11 }
12 } apply {
13 Controlled Z(Most(x), Tail(x));
14 }
15 }
16
17 @EntryPoint()
18 operation CheckSolution() : Bool {
19 for N in 1..4 {
20 for k in 0..((2^N)-1) {
21 let pattern = IntAsBoolArray(k, N);
22
23 let isCorrect = CheckOperationsEqualReferenced(
24 N,
25 Kata.ArbitraryBitPattern_Oracle_Challenge(_, pattern),
26 ArbitraryBitPattern_Oracle_Challenge_Reference(_, pattern));
27 if not isCorrect {
28 Message($"Failed on pattern {pattern}.");
29 return false;
30 }
31 }
32 }
33 Message("All tests passed.");
34 true
35 }
36
37}
38