mirror of
https://github.com/kucherenko/jscpd.git
synced 2026-09-19 08:11:03 +08:00
64e471e2b0
Adds 92 new tests (178 → 270 total) with zero source-file modifications: - packages/finder: 13 new test files covering all reporters, subscribers, validators, hooks, utils, options, cloneFound, getFilesToDetect, and InFilesDetector; shared buildClone() factory helper - apps/jscpd: 3 new test files (options-unit, print, store) plus extensions to formats, modes, and options integration tests - vitest.config.ts added to both packages to restrict coverage.include to src/** only, eliminating bin/ and prism.js noise - Fixes 3 tokenizer bugs (trailing space in format lookup, tokenization edge cases) uncovered by the new format fixture suite - Adds fixture files for 40+ language formats to support formats.test.ts
51 lines
1.3 KiB
Plaintext
51 lines
1.3 KiB
Plaintext
// Q# - Bernstein-Vazirani Algorithm
|
|
namespace BernsteinVazirani {
|
|
open Microsoft.Quantum.Canon;
|
|
open Microsoft.Quantum.Intrinsic;
|
|
open Microsoft.Quantum.Measurement;
|
|
|
|
// Prepare a Bell pair between two qubits
|
|
operation CreateBellPair(q1 : Qubit, q2 : Qubit) : Unit {
|
|
H(q1);
|
|
CNOT(q1, q2);
|
|
}
|
|
|
|
// Oracle encoding secret string s = "101"
|
|
operation BVOracle(queryReg : Qubit[], target : Qubit) : Unit {
|
|
// s = 101 => apply CNOT for bits 0 and 2
|
|
CNOT(queryReg[0], target);
|
|
CNOT(queryReg[2], target);
|
|
}
|
|
|
|
// Bernstein-Vazirani algorithm to find hidden string
|
|
operation FindHiddenString(n : Int) : Result[] {
|
|
use queryReg = Qubit[n];
|
|
use target = Qubit();
|
|
|
|
// Prepare target in |-> state
|
|
X(target);
|
|
H(target);
|
|
|
|
// Apply Hadamard to all query qubits
|
|
ApplyToEach(H, queryReg);
|
|
|
|
// Apply oracle
|
|
BVOracle(queryReg, target);
|
|
|
|
// Apply Hadamard again to query register
|
|
ApplyToEach(H, queryReg);
|
|
|
|
// Measure query register
|
|
let results = MultiM(queryReg);
|
|
Message($"Hidden string: {results}");
|
|
|
|
Reset(target);
|
|
return results;
|
|
}
|
|
|
|
@EntryPoint()
|
|
operation BVDemo() : Result[] {
|
|
return FindHiddenString(3);
|
|
}
|
|
}
|