Learning Scientific Programming with Python (2nd edition)

P3.2.2: The Gaussian Prime spiral

Question P3.2.2

A Gaussian integer is a complex number whose real and imaginary parts are both integers. A Gaussian prime is a Gaussian integer $x+iy$ such that either:

Consider the sequence of Gaussian integers traced out by an imaginary particle, initially at $c_0$, moving in the complex plane according to the following rule: it takes integer steps in its current direction ($\pm 1$ in either the real or imaginary direction), but turns left if it encounters a Gaussian prime. Its initial direction is in the positive real direction ($\Delta c = 1 + 0i\Rightarrow \Delta x = 1, \Delta y = 0$). The path traced out by the particle is called a Gaussian prime spiral.

Write a program to plot the Gaussian prime spiral starting at $c_0 = 5 + 23i$.