Links:

 

Starting out with PHP

Numbers from 1 to 49 placed in spiral order
Small Ulam spiral
Here's an odd thing:  suppose you make a pattern of integers starting from 1 and going up.  The first line is of length 1, then you turn left.  Next is length 1, turn left.  Next is length 2, turn left.  Then:  2, turn left; 3, turn left; 3, turn left; 4, turn left; etc.

Now do it only showing the prime numbers (below).  (This is called an "Ulam spiral," after Dr. Stanislaw Ulam.)  There sure are a lot of primes on the diagonals!  Wonder why?

Nobody knows, but let's see if we can draw a bigger spiral.  Here's how:  generate an array (see the PHP tutorial, on arrays for more help) in PHP that takes you up to 100 (using iteration -- don't fill it in by hand!), putting the numbers in a pattern like the one above.  Generate another array with line characters | and — -- you can use · for corners, since I don't have good corner symbols -- and fill in a spiral without numbers.  Then, for every number that is not prime, replace the number with the appropriate line character.

Then use PHP to create a table (this example can help)that has the spiral as its contents.  What happens if you start at some number other than one?

If you can go on to explain why the primes cluster on diagonals, let me know and I'll see about getting you in touch with the Nobel committee.