#Coding With Qiskit S2E5 Dinner Party using Grover's Algorithm

%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import *
from qiskit.aqua.algorithms import Grover
from qiskit.aqua.components.oracles import LogicalExpressionOracle
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from qiskit.tools.visualization import *
from qiskit.tools.monitor import job_monitor
# Loading your IBM Q account(s)
provider = IBMQ.load_account()

log_expr = '((Olivia & Abe) | (Jin & Amira)) & ~(Abe & Amira)'
algorithm = Grover(LogicalExpressionOracle(log_expr))

backend = BasicAer.get_backend('qasm_simulator')
result = algorithm.run(backend)
plot_histogram(result['measurement'], title="Possible Party Combinations", bar_labels=True)

#Top to bottom:
#Abe Amira Jin Oliva 

#Mapping to random Digital Logic Homework: F=(~A+~B+C)(~A+B+C)(A+~B+C)(A+B+~C)(A+B+C)

log_expr2 = '( ~A & ~B & C ) | ( ~A & B & C ) | ( A & ~B & C ) | ( A & B & ~C ) | ( A & B & C )'
algorithm2 = Grover(LogicalExpressionOracle(log_expr2))
result2 = algorithm2.run(backend)
plot_histogram(result2['measurement'], title="Homework:)", bar_labels=True)

#Matches with homework problem & LogicAid:)

