Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Refactor duplicate code in Grover's algorithm kata. (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmrazorea authored and tcNickolas committed Oct 26, 2018
1 parent 13705d3 commit 5486ea2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions GroversAlgorithm/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,22 @@ namespace Quantum.Kata.GroversAlgorithm
{
// flip the bits in odd (0-based positions),
// so that the condition for flipping the state of the target qubit is "query register is in 1...1 state"
for (n in 0..Length(queryRegister)-1)
{
if (n % 2 == 1)
{
X(queryRegister[n]);
}
}
FlipOddPositionBits_Reference(queryRegister);
(Controlled X)(queryRegister, target);
for (n in 0..Length(queryRegister)-1)
(Adjoint FlipOddPositionBits_Reference)(queryRegister);
}
adjoint auto;
}

operation FlipOddPositionBits_Reference (register : Qubit[]) : ()
{
body
{
for (i in 0..Length(register) - 1)
{
if (n % 2 == 1)
if (i % 2 == 1)
{
X(queryRegister[n]);
X(register[i]);
}
}
}
Expand Down

0 comments on commit 5486ea2

Please sign in to comment.