Solution (source code)

= Solution

Because $H_n|0^n\rangle=|\psi_0\rangle$,
$$
-H_nI_0H_n=2|\psi_0\rangle\langle\psi_0|-I,
$$
which is the <reflection operator> in the line spanned by $|\psi_0\rangle$. Meanwhile $I_G$ changes the sign of every good basis state and fixes every bad basis state; on
$$
\mathcal P=\operatorname{span}_{\mathbb R}\{|\psi_G\rangle,|\psi_B\rangle\}
$$
it is the reflection in the $|\psi_B\rangle$ axis. Both reflections preserve $\mathcal P$, so their product $Q$ does too.

Write
$$
|\psi_0\rangle
=\sqrt{\frac{k}{N}}|\psi_G\rangle
+\sqrt{\frac{N-k}{N}}|\psi_B\rangle
=\sin\theta|\psi_G\rangle+\cos\theta|\psi_B\rangle,
\qquad
\sin\theta=\sqrt{\frac{k}{N}}.
$$
In <Euclidean geometry>, the composition of reflections in two lines through the origin has a <rotation matrix> through twice the oriented angle between the lines. Hence $Q$ rotates the good-bad plane by $2\theta$ from $|\psi_B\rangle$ toward $|\psi_G\rangle$. In particular, the <Grover rotation angle> formula is
$$
\boxed{Q^r|\psi_0\rangle
=\sin((2r+1)\theta)|\psi_G\rangle
+\cos((2r+1)\theta)|\psi_B\rangle.}
$$