from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute, Aer, IBMQ
from qiskit.visualization import plot_histogram
IBMQ.save_account("APIKEY")

my_list=[1,3,5,6,7,8,23,56]
def the_oracle(my_input):
    winner=7
    if my_input is winner:
        response = True 
    else:
        response = False 
    return response
            

for index, trial_number in enumerate(my_list):
    if the_oracle(trial_number) is True:
        print('Winner found at index %i' %index)
        print('%i calls to the Oracle used' %(index+1))
        break
    

from qiskit import *
import matplotlib.pyplot as plt
import numpy as np

oracle = QuantumCircuit(2,name='oracle')
oracle.cz(0,1)
oracle.to_gate()
oracle.draw()

backend = Aer.get_backend('statevector_simulator')
grover_circ = QuantumCircuit(2,2)
grover_circ.h([0,1])
grover_circ.append(oracle,[0,1])
grover_circ.draw()

job = execute(grover_circ,backend)
result = job.result()

sv = result .get_statevector()
np.around(sv,2)

reflection = QuantumCircuit(2,name='reflection')
reflection.h([0,1])
reflection.z([0,1])
reflection.cz(0,1)
reflection.h([0,1])
reflection.to_gate()

reflection.draw()

backend = Aer.get_backend('qasm_simulator')
grover_circ = QuantumCircuit(2,2)
grover_circ.h([0,1])
grover_circ.append(oracle,[0,1])
grover_circ.append(reflection,[0,1])
grover_circ.measure([0,1],[0,1])

grover_circ.draw()

job=execute(grover_circ,backend,shots=1)
result=job.result()
result.get_counts()