Solution (source code)

= Solution

Let $B_E>0$ be the northward component of the ambient <magnetic field>. Define $\eta=+1$ if positive north-to-south current in A produces a northward field, and $\eta=-1$ otherwise. With opposite windings and the same signed current in both,
$$
B_N=B_E+\eta\frac{\mu_0(n_1-n_2)}sI.
$$
A compass reverses only when this northward component becomes negative. For current chosen to make the coil field southward,
$$
\boxed{|I|>I_{\rm crit}=\frac{B_Es}{\mu_0|n_1-n_2|}.}
$$
At equality the ideal axial field is zero and the needle has no preferred axial direction. If $n_1=n_2$, the opposing coil fields cancel and no finite current reverses it in this model. A numerical threshold cannot be given without $B_E$ and the coil parameters.