8123

This number is a prime.

Here's a fun play on StanisÅ‚aw Ulam's famous 1963 doodle:

Consider the construction of a counter-clockwise spiral formed by repeatedly writing the ten digits in increasing order (starting with 0, then placing the next digit(s) to the right, up, left, down, etc.) until an n-by-n lattice is obtained. Below is an example of a 4-by-4 (order-4).

5 ← 4 ← 3 ← 2
↑
4 ← 3 ← 2   1
↓       ↑   ↑     or    5  4  3  2
5   0 → 1   0           4  3  2  1
↓           ↑           5  0  1  0
6 → 7 → 8 → 9           6  7  8  9
The order-4 lattice contains exactly 18 distinct primes according to word search rules {2, 3, 5, 7, 11, 13, 17, 19, 23, 31, 43, 53, 67, 71, 89, 109, 307, 8123}.

What are the most that can be found on an order-5? A Primality Test will help!

6  5  4  3  2
7  4  3  2  1
8  5  0  1  0
9  6  7  8  9
0  1  2  3  4
Order-5 = ?. Solved by [your name here]

The sequence corresponding to the number of distinct primes occurring in an order-n lattice of this type begins 0, 5, 13, 18, ... .

Open question: At what order will this problem become computationally hard? Order-31?

Puzzle created by G. L. Honaker, Jr. © 2020.