diff --git a/Dockerfile b/Dockerfile index 2b02dc9..125cf15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/quantum/iqsharp-base:0.12.20092803 +FROM mcr.microsoft.com/quantum/iqsharp-base:0.15.2102.129448 ENV IQSHARP_HOSTING_ENV=QAZOO_DOCKER USER root diff --git a/README.md b/README.md index faab1f8..302c58f 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ Implementations of algorithms from http://quantumalgorithmzoo.org/ ## Index -| Algorithm | Speedup | Implementations | | -|--------------------|--------------------------------------------------|--------------------------------------|--| -| Factoring | Superpolynomial | [Q#](/src/qsharp/factoring) | | -| Bernstein-Vazirani | Polynomial Directly, Superpolynomial Recursively | [Q#](/src/qsharp/bernstein-vazirani) | | -| Searching | Polynomial | [Q#](/src/qsharp/searching) | | -| | | | | +| Algorithm | Speedup | Implementations | +|--------------------|--------------------------------------------------|--------------------------------------| +| Factoring | Superpolynomial | [Q#](/src/qsharp/factoring) | +| Bernstein-Vazirani | Polynomial Directly, Superpolynomial Recursively | [Q#](/src/qsharp/bernstein-vazirani) | +| Searching | Polynomial | [Q#](/src/qsharp/searching) | +| Counterfeit coins | Polynomial | [Q#](/src/qsharp/counterfeit-coins) | ## TODOs: -- [ ] Add doc strings \ No newline at end of file +- [ ] Add doc strings diff --git a/src/qsharp/counterfeit-coins/CounterfeitCoins.csproj b/src/qsharp/counterfeit-coins/CounterfeitCoins.csproj new file mode 100644 index 0000000..f9a6634 --- /dev/null +++ b/src/qsharp/counterfeit-coins/CounterfeitCoins.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/src/qsharp/counterfeit-coins/Program.qs b/src/qsharp/counterfeit-coins/Program.qs new file mode 100644 index 0000000..25921d9 --- /dev/null +++ b/src/qsharp/counterfeit-coins/Program.qs @@ -0,0 +1,55 @@ +namespace CounterfeitCoins { + + open Microsoft.Quantum.Arithmetic; + open Microsoft.Quantum.Logical; + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Arrays; + open Microsoft.Quantum.Canon; + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Bitwise; + +/// N coin total in the bag, k coins are counterfeit. +/// https://arxiv.org/pdf/1009.0416.pdf +/// + @EntryPoint() + operation FindCounterfeits(numCoins : Int, numCounterfeit : Int) : Int { + //1. Setup register + use register1 = Qubit[numCoins]; + // Apply W + within { + ApplyW(register1, numCoins); + } + apply { + //2. + use register2 = Qubit[numCoins]; + //ApplyA(register2); + //ControlledOnBitString(TBD, register2); + + } + //3. + return MeasureInteger(LittleEndian(register1)); + + } + + operation ApplyW(target : Qubit[], numCoins : Int) : Unit + is Adj + Ctl { + //Generate list of all integers up to N + //let QEven = Filtered(Compose(EqualI(0, _), Parity), + // RangeAsIntArray(0..numCoins)); + let most = Most(target); + ApplyToEachCA(H, most); + // |uniform⟩|0⟩ + ApplyToEachCA(CNOT(Tail(target), _), most); + // + } + + operation ApplyR( + control : Qubit[], + target : LittleEndian) + : Unit is Adj + Ctl { + // R |i_0, i_1, i_2,..i_N⟩|0⟩ - > |i⟩|wt(i)⟩ + // wt() = the number of 1's in your bitstring + let arrayControl = Mapped(ConstantArray(1, _), control); + ApplyToEachCA((Controlled IncrementByInteger)(_ ,(1, target)) , arrayControl); + } +}