[Tutor] Primes on a two-dimensional plane in the form of arectangular spiral

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 9 Apr 2001 13:56:16 -0700 (PDT)


Here's one more experiment after I played around with the spiraling
function.  Take a look!

###
>>> def a(n): return 2 * n * (1+2*n)
... 
>>> def getNum(x, y):
...     if abs(x) <= abs(y): return a(-y) + abs(y-x)
...     else: return a(-x) - abs(y-x)
... 
>>> for y in range(5, -5, -1):
...     for x in range(-5, 5):
...         print "%5d" % getNum(x, y),
...     print
... 
  100    99    98    97    96    95    94    93    92    91
  101    64    63    62    61    60    59    58    57    56
  102    65    36    35    34    33    32    31    30    55
  103    66    37    16    15    14    13    12    29    54
  104    67    38    17     4     3     2    11    28    53
  105    68    39    18     5     0     1    10    27    52
  106    69    40    19     6     7     8     9    26    51
  107    70    41    20    21    22    23    24    25    50
  108    71    42    43    44    45    46    47    48    49
  109    72    73    74    75    76    77    78    79    80
###

There is a Mathgod, after all.  *grin*


Actually, I finally did the generating function way of deriving the
function a(n).  If anyone's interested, I'll be glad to post a .pdf to the
math.

Ok, this was overkill, but I had fun doing it.