diff --git a/Counting/Counting.csproj b/Counting/Counting.csproj
new file mode 100644
index 00000000000..73fc33c211d
--- /dev/null
+++ b/Counting/Counting.csproj
@@ -0,0 +1,23 @@
+
+
+ netcoreapp2.1
+ x64
+ false
+ Quantum.Kata.Counting
+ Counting
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Counting/Counting.ipynb b/Counting/Counting.ipynb
new file mode 100644
index 00000000000..cca0d52a735
--- /dev/null
+++ b/Counting/Counting.ipynb
@@ -0,0 +1,316 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Counting\n",
+ "\n",
+ "\n",
+ "\n",
+ "The **Quantum Counting** quantum kata is a series of exercises designed\n",
+ "to get you familiar with quantum counting algorithm.\n",
+ "\n",
+ "It covers the following topics:\n",
+ "\n",
+ "* writing oracles for counting,\n",
+ "* performing actual counting.\n",
+ " \n",
+ "\n",
+ "*Reading material:*\n",
+ "\n",
+ "* The tasks follow the explanation from *Quantum Computation and Quantum Information* by Nielsen and Chuang.\n",
+ " In the 10th anniversary edition, this is section 6.3 on pages 261-263.\n",
+ " \n",
+ "Each task is wrapped in one operation preceded by the description of the task.\n",
+ "Your goal is to fill in the blanks (marked with the `// ...` comments)\n",
+ "with some Q# code that solves the task. To verify your answer, run the cell with Ctrl/⌘+Enter.\n",
+ "\n",
+ "Within each section, tasks are given in approximate order of increasing difficulty;\n",
+ "harder ones are marked with asterisks."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "To begin, first prepare this notebook for execution (if you skip this step, you'll get \"Syntax does not match any known patterns\" error when you try to execute Q# code in the next cells):"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%package Microsoft.Quantum.Katas::0.8.1907.1701\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "> The package versions in the output of the cell above should always match. If you are running the Notebooks locally and the versions do not match, please install the IQ# version that matches the version of the `Microsoft.Quantum.Katas` package.\n",
+ "> \n",
+ "> How to install the right IQ# version
\n",
+ "> For example, if the version of `Microsoft.Quantum.Katas` package above is 0.1.2.3, the installation steps are as follows:\n",
+ ">\n",
+ "> 1. Stop the kernel.\n",
+ "> 2. Uninstall the existing version of IQ#:\n",
+ "> dotnet tool uninstall microsoft.quantum.iqsharp -g\n",
+ "> 3. Install the matching version:\n",
+ "> dotnet tool install microsoft.quantum.iqsharp -g --version 0.1.2.3\n",
+ "> 4. Reinstall the kernel:\n",
+ "> dotnet iqsharp install\n",
+ "> 5. Restart the Notebook.\n",
+ "> \n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Part I. Oracle Counting\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Task 1.1. The Sprinkler oracle\n",
+ "\n",
+ "Let us consider an example inspired by the sprinkler problem of (Pearl 1988): \n",
+ "we have three Boolean variable, $s$, $r$, $w$ representing respectively propositions \n",
+ "“the sprinkler was on”, \"ıt rained last night” and “the grass is wet”. \n",
+ "We know that if the sprinkler was on the grass is wet ($s \\to w$), \n",
+ "if it rained last night the grass is wet ($r \\to w$) \n",
+ "and that the the sprinkler being on and rain last night cannot be true at the same time ($s, r \\to$).\n",
+ "Transformed in conjunctive normal formal we obtain formula $(\\neg s \\vee w) \\wedge (\\neg r \\vee w) \\wedge\n",
+ "(\\neg s \\vee \\neg r)$.\n",
+ "Let $s,r,w$=`queryRegister[0],queryRegister[1],queryRegister[2]`\n",
+ "Hint: to solve this task you also need to use ancilla qubits\n",
+ "This formula has 4 models out of 8 possible worlds.\n",
+ "\n",
+ "
\n",
+ "\n",
+ " Need a hint? Click here
\n",
+ " Here is what the circuit looks like\n",
+ "
\n",
+ " \n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/snippet:(1,26): error QS6104: No namespace with that name exists.\n",
+ "/snippet:(3,10): error QS6104: No namespace with that name exists.\n",
+ "/snippet:(14,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(15,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(16,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(17,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(19,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(20,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(21,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(22,17): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(23,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(24,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(25,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(27,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(28,5): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(29,5): error QS5022: No identifier with that name exists.\n"
+ ]
+ }
+ ],
+ "source": [
+ "%kata T11_Oracle_Sprinkler_Test \n",
+ "\n",
+ "\n",
+ "operation Oracle_Sprinkler (queryRegister : Qubit[], target : Qubit, ancilla : Qubit[]) : Unit\n",
+ " { \n",
+ "\t body (...) {\n",
+ "\t\t\t\tX(queryRegister[2]);\n",
+ "\t\t\t\tX(ancilla[0]);\n",
+ "\t\t\t\tX(ancilla[1]);\n",
+ "\t\t\t\tX(ancilla[2]);\n",
+ " \n",
+ "\t\t\t\tCCNOT(queryRegister[0],queryRegister[1],ancilla[0]);\n",
+ "\t\t\t\tCCNOT(queryRegister[1],queryRegister[2],ancilla[1]);\n",
+ "\t\t\t\tCCNOT(queryRegister[0],queryRegister[2],ancilla[2]);\n",
+ "\t\t\t\t(Controlled X)([ancilla[0],ancilla[1],ancilla[2]],target);\n",
+ "\t\t\t\tCCNOT(queryRegister[0],queryRegister[2],ancilla[2]);\n",
+ "\t\t\t\tCCNOT(queryRegister[1],queryRegister[2],ancilla[1]);\n",
+ "\t\t\t\tCCNOT(queryRegister[0],queryRegister[1],ancilla[0]);\n",
+ "\n",
+ "\t\t\t\tX(ancilla[2]);\n",
+ "\t\t\t\tX(ancilla[1]);\n",
+ "\t\t\t\tX(ancilla[0]); \n",
+ " }\n",
+ "\t\t\tadjoint invert;\n",
+ "\t\t\tcontrolled auto;\n",
+ "\t\t\tcontrolled adjoint auto;\n",
+ " }"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "## Part II. Counting"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Task 2.1. Implement counting using operations from ReferenceImplementation.qs\n",
+ "* UnitaryPowerImpl, for computing powers of a unitary operation\n",
+ "* GroverIteration for the Grover operator\n",
+ "* QuantumPhaseEstimation, for estimating the phase\n",
+ "* Counting should return the number of models, 4 in this case\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/snippet:(1,26): error QS6104: No namespace with that name exists.\n",
+ "/snippet:(7,27): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(7,43): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(9,22): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(9,37): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(9,54): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(14,35): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(16,17): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(19,13): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(21,25): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(21,37): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(21,52): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(21,97): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(23,13): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(24,13): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(26,21): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(27,20): error QS5022: No identifier with that name exists.\n",
+ "/snippet:(27,25): error QS5022: No identifier with that name exists.\n"
+ ]
+ }
+ ],
+ "source": [
+ " operation Counting() : Double {\n",
+ " mutable phase = -1.0;\n",
+ " let n=4;\n",
+ " using ((reg,phaseRegister,ancilla)=(Qubit[3],Qubit[n],Qubit[3]))\n",
+ " {\n",
+ " // Construct a phase estimation oracle from the unitary\n",
+ " let phaseOracle = OracleConverter(Oracle_Sprinkler_Reference(_,_,ancilla));\n",
+ "\n",
+ " let oracle = DiscreteOracle(UnitaryPowerImpl(GroverIteration(_, phaseOracle), _, _));\n",
+ "\n",
+ "\n",
+ " // Allocate qubits to hold the eigenstate of U and the phase in a big endian register \n",
+ " \n",
+ " let phaseRegisterBE = BigEndian(phaseRegister);\n",
+ " // Prepare the eigenstate of U\n",
+ " HadamardTransform(reg);\n",
+ "//should return 0.5\n",
+ " // Call library\n",
+ " QuantumPhaseEstimation(oracle, reg, phaseRegisterBE);\n",
+ " // Read out the phase\n",
+ " set phase = IntAsDouble(MeasureInteger(BigEndianAsLittleEndian(phaseRegisterBE))) / IntAsDouble(1 <<< (n));\n",
+ "\n",
+ " ResetAll(reg);\n",
+ " ResetAll(phaseRegister);\n",
+ " }\n",
+ " let angle = PI()*phase;\n",
+ " let res = (PowD(Sin(angle),2.0));\n",
+ "\n",
+ " return 8.0*res;\n",
+ " }\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Task 3.2. Using Counting \n",
+ "\n",
+ "**Goal:** Use your implementation of Counting from Task 2.1 and the oracle from part 1\n",
+ " to find the number of solutions of the sprinkler problem. This task is not covered by a test and allows you to experiment with running the algorithm.\n",
+ " \n",
+ "> This is an open-ended task, and is not covered by a unit test. To run the code, execute the cell with the definition of the `Run_Counting` operation first; if it compiled successfully without any errors, you can run the operation by executing the next cell (`%simulate Run_GroversSearch_Algorithm`).\n",
+ "\n",
+ "> Note that this task relies on your implementations of the previous tasks. If you are getting the \"No variable with that name exists.\" error, you might have to execute previous code cells before retrying this task.\n",
+ "\n",
+ "
\n",
+ "\n",
+ " Hint #3
\n",
+ " You can use the Message function to output the results.\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ " operation Run_Counting() : Unit {\n",
+ "\n",
+ "\t\tlet res=Counting();\n",
+ " Message(DoubleAsString(res));\n",
+ "\n",
+ " }\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Invalid operation name: Run_Counting\n"
+ ]
+ }
+ ],
+ "source": [
+ "%simulate Run_Counting"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Q#",
+ "language": "qsharp",
+ "name": "iqsharp"
+ },
+ "language_info": {
+ "file_extension": ".qs",
+ "mimetype": "text/x-qsharp",
+ "name": "qsharp",
+ "version": "0.4"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/Counting/Counting.sln b/Counting/Counting.sln
new file mode 100644
index 00000000000..afeba3f998a
--- /dev/null
+++ b/Counting/Counting.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.28729.10
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Counting", "Counting.csproj", "{4BAAB76A-ABFA-4F5C-9E5B-788BB3E8647E}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {4BAAB76A-ABFA-4F5C-9E5B-788BB3E8647E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4BAAB76A-ABFA-4F5C-9E5B-788BB3E8647E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4BAAB76A-ABFA-4F5C-9E5B-788BB3E8647E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4BAAB76A-ABFA-4F5C-9E5B-788BB3E8647E}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {7CB0806C-1BBF-4E0C-BDFC-04A9A068F41C}
+ EndGlobalSection
+EndGlobal
diff --git a/Counting/README.md b/Counting/README.md
new file mode 100644
index 00000000000..9a7f9cb5fbf
--- /dev/null
+++ b/Counting/README.md
@@ -0,0 +1,11 @@
+# Welcome!
+
+The Counting kata covers the quantum counting algorithm, which is based on Grover's search algorithm.
+It solves the problem of computing the number of assignments of Boolean input variables
+that make a Boolean function (oracle) true.
+
+#### Theory
+
+* The tasks follow the explanation from *Quantum Computation and Quantum Information* by Nielsen and Chuang.
+ In the 10th anniversary edition, this is section 6.3 on pages 261-263.
+
diff --git a/Counting/ReferenceImplementation.qs b/Counting/ReferenceImplementation.qs
new file mode 100644
index 00000000000..9657b5ac147
--- /dev/null
+++ b/Counting/ReferenceImplementation.qs
@@ -0,0 +1,103 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+//////////////////////////////////////////////////////////////////////
+// This file contains reference solutions to all tasks.
+// The tasks themselves can be found in Tasks.qs file.
+// We recommend that you try to solve the tasks yourself first,
+// but feel free to look up the solution if you get stuck.
+//////////////////////////////////////////////////////////////////////
+
+namespace Quantum.Kata.Counting {
+
+ open Microsoft.Quantum.Arrays;
+ open Microsoft.Quantum.Intrinsic;
+ open Microsoft.Quantum.Canon;
+ open Microsoft.Quantum.Math;
+ open Microsoft.Quantum.Oracles;
+ open Microsoft.Quantum.Convert;
+ open Microsoft.Quantum.Arithmetic;
+ open Microsoft.Quantum.Characterization;
+
+
+ //////////////////////////////////////////////////////////////////
+ // Part I. Oracle for Counting
+ //////////////////////////////////////////////////////////////////
+
+ operation Oracle_Solution_Count_Reference (queryRegister : Qubit[], target : Qubit, nSol : Int) : Unit is Ctl+ Adj {
+ // Designate first nSol integers solutions (since we don't really care which ones are solutions)
+ for (i in 0 .. nSol - 1) {
+ (ControlledOnInt(i, X))(queryRegister, target);
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////
+ // Part II. The Grover iteration
+ //////////////////////////////////////////////////////////////////
+
+
+ // Helper operation which converts marking oracle into phase oracle using an extra qubit
+ operation ApplyMarkingOracleAsPhaseOracle (markingOracle : ((Qubit[], Qubit) => Unit is Ctl+Adj), register : Qubit[]) : Unit is Adj+Ctl {
+ using (target = Qubit()) {
+ // Put the target into the |-⟩ state
+ X(target);
+ H(target);
+
+ // Apply the marking oracle; since the target is in the |-⟩ state,
+ // flipping the target if the register satisfies the oracle condition will apply a -1 factor to the state
+ markingOracle(register, target);
+
+ // Put the target back into |0⟩ so we can return it
+ H(target);
+ X(target);
+ }
+ }
+
+ // The Grover iteration
+ operation GroverIteration (register : Qubit[], oracle : ((Qubit[],Qubit) => Unit is Ctl+Adj)) : Unit is Ctl+Adj
+ {
+
+ // apply oracle
+ ApplyMarkingOracleAsPhaseOracle(oracle, register);
+ // apply inversion about the mean
+ ApplyToEachCA(H, register);
+ ApplyToEachCA(X, register);
+ Controlled Z(Most(register), Tail(register));
+ ApplyToEachCA(X, register);
+ R(PauliI, 2.0 * PI(), register[0]);
+ ApplyToEachCA(H, register);
+ }
+
+
+ //////////////////////////////////////////////////////////////////
+ // Part III. Putting it all together: Quantum Counting
+ //////////////////////////////////////////////////////////////////
+
+
+ operation Counting_Reference(n_bit : Int, n_sol: Int, precision: Int) : Double {
+ mutable phase = -1.0;
+
+ using ((register,phaseRegister)=(Qubit[n_bit],Qubit[precision]))
+ // Allocate qubits to hold the eigenstate of U and the phase in a big endian register
+ {
+ let oracle = OracleToDiscrete(GroverIteration(_, Oracle_Solution_Count_Reference(_,_,n_sol)));
+
+
+ let phaseRegisterBE = BigEndian(phaseRegister);
+ // Prepare the eigenstate of U
+ ApplyToEach(H, register);
+ // Call library
+ QuantumPhaseEstimation(oracle, register, phaseRegisterBE);
+ // Read out the phase
+ set phase = IntAsDouble(MeasureInteger(BigEndianAsLittleEndian(phaseRegisterBE))) / IntAsDouble(1 <<< (precision));
+
+ ResetAll(register);
+ ResetAll(phaseRegister);
+ }
+ let angle = PI()*phase;
+ let res = (PowD(Sin(angle),2.0));
+
+ return PowD(2.0,IntAsDouble(n_bit))*res;
+ }
+
+}
diff --git a/Counting/Tasks.qs b/Counting/Tasks.qs
new file mode 100644
index 00000000000..4bc634ffcfb
--- /dev/null
+++ b/Counting/Tasks.qs
@@ -0,0 +1,63 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+namespace Quantum.Kata.Counting {
+
+ open Microsoft.Quantum.Diagnostics;
+ open Microsoft.Quantum.Convert;
+ open Microsoft.Quantum.Math;
+ open Microsoft.Quantum.Intrinsic;
+ open Microsoft.Quantum.Canon;
+ open Microsoft.Quantum.Oracles;
+ open Microsoft.Quantum.Arithmetic;
+ open Microsoft.Quantum.Characterization;
+
+
+ //////////////////////////////////////////////////////////////////
+ // Welcome!
+ //////////////////////////////////////////////////////////////////
+
+ // The "Counting" quantum kata is a series of exercises designed
+ // to get you familiar with Quantum Counting.
+ // It covers the following topics:
+ // - writing oracles for counting,
+ // - performing actual counting.
+
+ // Each task is wrapped in one operation preceded by the description of the task.
+ // Each task (except tasks in which you have to write a test) has a unit test associated with it,
+ // which initially fails. Your goal is to fill in the blank (marked with // ... comment)
+ // with some Q# code to make the failing test pass.
+
+ // Within each section, tasks are given in approximate order of increasing difficulty;
+ // harder ones are marked with asterisks.
+
+
+ //////////////////////////////////////////////////////////////////
+ // Part I. Oracle for Counting
+ //////////////////////////////////////////////////////////////////
+
+ // Task 1.1. The solution count oracle
+ // Designate first nSol integers solutions (since we don't really care which ones are solutions)
+
+ operation Oracle_Solution_Count (queryRegister : Qubit[], target : Qubit, nSol : Int) : Unit is Ctl+ Adj {
+ //
+ }
+
+ //////////////////////////////////////////////////////////////////
+ // Part I. Counting
+ //////////////////////////////////////////////////////////////////
+ // Implement counting using operations from ReferenceImplementation.qs
+ // - GroverIteration (register : Qubit[], oracle : ((Qubit[],Qubit) => Unit is Ctl+Adj)) : Unit is Ctl+Ad
+ // for the Grover operator
+ // - QuantumPhaseEstimation (oracle : Microsoft.Quantum.Oracles.DiscreteOracle, targetState : Qubit[], controlRegister : Microsoft.Quantum.Arithmetic.BigEndian) : Unit
+ // from Microsoft.Quantum.Characterization, for estimating the phase
+ // Counting should return the number of models, n_sol
+ operation Counting(n_bit : Int, n_sol: Int, precision: Int) : Double {
+ // ....
+ return 0.0;
+ }
+
+
+
+
+}
diff --git a/Counting/TestSuiteRunner.cs b/Counting/TestSuiteRunner.cs
new file mode 100644
index 00000000000..12ba97b04a9
--- /dev/null
+++ b/Counting/TestSuiteRunner.cs
@@ -0,0 +1,42 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+//////////////////////////////////////////////////////////////////////
+// This file contains parts of the testing harness.
+// You should not modify anything in this file.
+// The tasks themselves can be found in Tasks.qs file.
+//////////////////////////////////////////////////////////////////////
+
+using Microsoft.Quantum.Simulation.XUnit;
+using Microsoft.Quantum.Simulation.Simulators;
+using Xunit.Abstractions;
+using System.Diagnostics;
+
+namespace Quantum.Kata.Counting
+{
+ public class TestSuiteRunner
+ {
+ private readonly ITestOutputHelper output;
+
+ public TestSuiteRunner(ITestOutputHelper output)
+ {
+ this.output = output;
+ }
+
+ ///
+ /// This driver will run all Q# tests (operations named "...Test")
+ /// that belong to namespace Quantum.Kata.Counting.
+ ///
+ [OperationDriver(TestNamespace = "Quantum.Kata.Counting")]
+ public void TestTarget(TestOperation op)
+ {
+ using (var sim = new QuantumSimulator())
+ {
+ // OnLog defines action(s) performed when Q# test calls function Message
+ sim.OnLog += (msg) => { output.WriteLine(msg); };
+ sim.OnLog += (msg) => { Debug.WriteLine(msg); };
+ op.TestOperationRunner(sim);
+ }
+ }
+ }
+}
diff --git a/Counting/Tests.qs b/Counting/Tests.qs
new file mode 100644
index 00000000000..ab6e7630c92
--- /dev/null
+++ b/Counting/Tests.qs
@@ -0,0 +1,63 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+//////////////////////////////////////////////////////////////////////
+// This file contains testing harness for all tasks.
+// You should not modify anything in this file.
+// The tasks themselves can be found in Tasks.qs file.
+//////////////////////////////////////////////////////////////////////
+
+namespace Quantum.Kata.Counting {
+
+ open Microsoft.Quantum.Arrays;
+ open Microsoft.Quantum.Canon;
+ open Microsoft.Quantum.Diagnostics;
+ open Microsoft.Quantum.Convert;
+ open Microsoft.Quantum.Math;
+ open Microsoft.Quantum.Intrinsic;
+
+
+ operation Compute_Average(n_bit : Int, n_sol: Int, precision: Int, iterations: Int, tolerance_fraction: Double): Unit
+ {
+ mutable sum=0.0;
+ let tolerance=tolerance_fraction*IntAsDouble(n_sol);
+
+ for (i in 1..iterations)
+ {
+ let reference=Counting(n_bit,n_sol,precision);
+ Message(DoubleAsString(reference));
+ set sum=sum+reference;
+ }
+ let average=sum/IntAsDouble(iterations);
+ Message("Expected :"+IntAsString(n_sol)+" Found (average): "+DoubleAsString(average));
+ EqualityWithinToleranceFact(average,IntAsDouble(n_sol),tolerance);
+ }
+
+ // ------------------------------------------------------
+ operation T7_16_5_Counting_Test () : Unit {
+ let iterations=10;
+ let n_bit=7;
+ let n_sol=16;
+ let precision=5;
+ let tolerance_fraction=0.7;
+ Compute_Average(n_bit,n_sol,precision,iterations,tolerance_fraction);
+ }
+
+ operation T7_20_5_Counting_Test () : Unit {
+ let iterations=10;
+ let n_bit=7;
+ let n_sol=20;
+ let precision=5;
+ let tolerance_fraction=0.7;
+ Compute_Average(n_bit,n_sol,precision,iterations,tolerance_fraction);
+ }
+
+ operation T7_40_5_Counting_Test () : Unit {
+ let iterations=10;
+ let n_bit=7;
+ let n_sol=40;
+ let precision=5;
+ let tolerance_fraction=0.7;
+ Compute_Average(n_bit,n_sol,precision,iterations,tolerance_fraction);
+ }
+}
diff --git a/Counting/sprinkler.png b/Counting/sprinkler.png
new file mode 100644
index 00000000000..e6e5f7bb6db
Binary files /dev/null and b/Counting/sprinkler.png differ