microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/marking_oracles/majority/Verification.qs
22lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Katas; |
| 3 | open Microsoft.Quantum.Arrays; |
| 4 | |
| 5 | function F_Majority(args : Bool[]) : Bool { |
| 6 | let N = Length(args); |
| 7 | return Count(x -> x, args) > (N - 1) / 2; |
| 8 | } |
| 9 | |
| 10 | @EntryPoint() |
| 11 | operation CheckSolution() : Bool { |
| 12 | for n in [3, 5, 7] { |
| 13 | if not CheckOracleImplementsFunction(n, Kata.Oracle_Majority, F_Majority) { |
| 14 | Message($"Test failed for n = {n}"); |
| 15 | return false; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | Message("Correct!"); |
| 20 | true |
| 21 | } |
| 22 | } |
| 23 | |