// --- 3-SAT — niespełniający kryteriów
var num_qubits = 3;
var num_ancilla = 4;

qc.reset(num_qubits+num_ancilla);
var reg = qint.new(num_qubits, 'reg');
qc.write(0);

reg.hadamard();

// przypadek 1
bit_or(0x1,0x2,0x8);

// przypadek 2
qc.not(0x1);
bit_or(0x1,0x4,0x10);
qc.not(0x1);

// przypadek 3
qc.not(0x2|0x4);
bit_or(0x2,0x4,0x20);
qc.not(0x2|0x4);

// przypadek 4
bit_or(0x1,0x4,0x40);

// flip fazy
phase_and(0x2|0x8|0x10|0x20|0x40);

// odwróć przypadek 4
inv_bit_or(0x1,0x4,0x40);

// odwróć przypadek 3
qc.not(0x2|0x4);
inv_bit_or(0x2,0x4,0x20);
qc.not(0x2|0x4);

// odwróć przypadek 2
qc.not(0x1);
inv_bit_or(0x1,0x4,0x10);
qc.not(0x1);

// odwróć przypadek 1
inv_bit_or(0x1,0x2,0x8);
reg.Grover();

///////////////// Definicje
// Zdefiniuj bit OR i odwrotność
function bit_or(q1, q2, out) {
    qc.not(q1|q2);
    qc.cnot(out,q1|q2);
    qc.not(q1|q2|out);
}

function inv_bit_or(q1, q2, out) {
    qc.not(q1|q2|out);
    qc.cnot(out,q1|q2);
    qc.not(q1|q2);
}

// Zdefiniuj fazę AND
function phase_and(qubits) {
    qc.cz(qubits);
}
