static void Main(string[] args) { int ones = 0; // We initialize a Quantum Simulator same as before using (var qsim = new QuantumSimulator()) { // We run a loop for 1000 times to test the phenomenon for (int i = 0; i < 1000; i++) { // We run the Superposition operation and store the returned result in the respective varialble var result = Superposition.Run(qsim).Result; // Check if the value of the resultant state is 1 if (result == Result.One) { ones++; } } } // Print the number of times the resultant state has assumed the value of 0 and 1. They should be nearly 50% of the time. Console.WriteLine("Collapsed States: "); Console.WriteLine($"One: {ones}"); Console.WriteLine($"Zero: {1000 - ones}"); Console.ReadKey(); }
static void Main(string[] args) { // Use quantum simulator to create a superposition state and // measure it in the computational basis using (var sim = new QuantumSimulator()) { Result outcome = Superposition.Run(sim).Result; System.Console.WriteLine($"Measuring equal superposition state gave outcome {outcome}."); } System.Console.WriteLine("Press any key to continue..."); System.Console.ReadKey(); }
static void Main(string[] args) { int ones = 0; using (var qsim = new QuantumSimulator()) { for (int index = 0; index < 1000; index++) { var result = Superposition.Run(qsim).Result; if (result == Result.One) { ones++; } } } Console.WriteLine("Collapsed States: "); Console.WriteLine($"\t One: {ones} "); Console.WriteLine($"\t Zero: {1000 - ones} "); Console.ReadKey(); }