Skip to content

Commit 338d692

Browse files
up
1 parent d01b849 commit 338d692

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,21 @@ To construct an oracle for this application, we only need to be able to find a s
499499
In the above examples for even and odd numbers, we knew exactly which qubit to flip (qubit 0). This time, we need to flip [specific](https://github.com/primaryobjects/oracle/blob/master/lib/oracles/numeric.py) qubits, based upon the target value. This can be done by converting the value from base-10 to a binary string and then flipping the resulting qubits accordingly to their corresponding bit values.
500500

501501
```python
502+
# Choose a (random) target answer.
503+
i = 6
504+
505+
# Convert i to a binary string, pad with zeros, and reverse for qiskit.
506+
bin_str = bin(i)[2:]
507+
bin_str = bin_str.zfill(n)
508+
bin_str = bin_str[::-1]
509+
502510
# Flip each qubit to zero to match the bits in the target number i.
503511
for j in range(len(bin_str)):
504512
if bin_str[j] == '0':
505513
qc.x(j)
506514

507515
qc.append(ZGate().control(n), range(n+1))
508516

509-
510517
# Unflip each qubit to zero to match the bits in the target number i.
511518
for j in range(len(bin_str)):
512519
if bin_str[j] == '0':

0 commit comments

Comments
 (0)