Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JesusCastroFernandez/70d4e80e800c56a2d2937505fbdd751b to your computer and use it in GitHub Desktop.
Save JesusCastroFernandez/70d4e80e800c56a2d2937505fbdd751b to your computer and use it in GitHub Desktop.
Ejemplo de código cuántico en Q# que muestra cómo implementar el algoritmo de Grover para buscar una entrada en una lista no estructurada
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Search;
operation GroverSearch() : Unit {
// Define the list to search.
let markedElements = [1, 3];
// Define the number of qubits needed to represent the list.
let nQubits = 2;
// Allocate qubits.
using (qubits = Qubit[nQubits]) {
// Prepare the initial state.
ApplyToEach(H, qubits);
// Apply the Grover iteration.
GroverIteration(markedElements, qubits);
// Measure the result.
let result = MultiM(qubits);
// Print the result.
Message($"Result: {result}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment