Created
May 14, 2020 19:09
-
-
Save billchenxi/c276d0ebfcfd58381b64310c8620916e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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