Skip to content

Instantly share code, notes, and snippets.

@billchenxi
Created May 14, 2020 19:09
Show Gist options
  • Save billchenxi/c276d0ebfcfd58381b64310c8620916e to your computer and use it in GitHub Desktop.
Save billchenxi/c276d0ebfcfd58381b64310c8620916e to your computer and use it in GitHub Desktop.
namespace Q_superposition {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
operation Superposition() : Result {
mutable state = Zero;
using (qubit = Qubit()) {
H(qubit);
set state = M(qubit);
Reset(qubit);
}
return state;
}
operation QuantumSimulator() : Int {
let count = 1000;
mutable ones = 0;
for (indx in 1..count) {
if (Superposition() == One) {
set ones += 1;
}
}
return ones;
}
@EntryPoint()
operation Driver_Code() : Unit {
let ones = QuantumSimulator();
let zeros = 1000-ones;
Message($"Collapsed States: ");
Message($" One: {ones}");
Message($" Zero: {zeros}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment