Created
May 26, 2023 11:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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