Oracle[ket_]:=If[ket==336," The Oracle has found the ket | 336 ⟩ "," Sorry try again "]
zerobit={1,0};
onebit={0,1};
nullket=Flatten[KroneckerProduct[zerobit,zerobit,zerobit,zerobit,zerobit,zerobit,zerobit,zerobit,zerobit,zerobit]];

Hadamard=1/Sqrt[2]{{1,1},{1,-1}};

Hadtimesn=KroneckerProduct[Hadamard,Hadamard,Hadamard,Hadamard,Hadamard,Hadamard,Hadamard,Hadamard,Hadamard,Hadamard];

MatrixForm[Hadtimesn];
phi=Hadtimesn.nullket;

V=DiagonalMatrix[Table[If[i==337,-1,1],{i,1,2^10}]];
(* in order to construct W it is easiest to use definition above *)

W=2 KroneckerProduct[phi,phi]-IdentityMatrix[2^10];
(* Grover operator G = W V *)
G=W.V;

kets=Table[StringJoin[{"|",IntegerString[i-1],"⟩"}],{i,1,1024}];

Qrun:=Module[{},iteration=iteration+1;Print["Number of iterations = ",iteration];grover=N[G.grover];];

M[grover_]:=Module[{},Print["The oracle has found the ket -->"]; RandomChoice[grover^2->kets]]

Classical vs Quantum

We have an n=10 bit register and we are looking, using the oracle, a given ket  | x ⟩.  We will have two
groups, the classisicts who will invoke the oracle using the command

Oracle[1]

(* First Grover iteration *)
grover=G.phi;
iteration=1;

The Groverites will use the Grover iteration and then take a measurement

Hint: the optimum number of runs through the Grover operator is
given by the expression     π/4 (Sqrt[N]) where N=(2^n)

When you feel comfortable with the number of iterations necessary to converge to the correct answer,
take a measurement   using the command  M[grover]

Qrun

M[grover]