The previous post showed how to list all limerick primes. This post shows how to list all sonnet primes. These are primes of the form *ababcdcdefefgg*, the rhyme scheme of an English (Shakespearean) sonnet, where the letters *a* through *g* represent digits and *a* is not zero.

Here’s the Mathematica code.

number[s_] := 10100000000000 s[[1]] + 1010000000000 s[[2]] + 1010000000 s[[3]] + 101000000 s[[4]] + 101000 s[[5]] + 10100 s[[6]] + 11 s[[7]] test[n_] := n > 10^13 && PrimeQ[n] candidates = Permutations[Table[i, {i, 0, 9}], {7}]; list = Select[Map[number, candidates], test];

The function `Permutations[`

*list*, {n}`]`

creates a list of all permutations of *list* of length *n*. In this case we create all permutations the digits 0 through 9 that have length 7. These are the digits *a* through *g*.

The function `number`

turns the permutation into a number. This function is applied to each candidate. We then select all 14-digit prime numbers from the list of candidates using `test`

.

If we ask for `Length[list]`

we see there are 16,942 sonnet primes.

As mentioned before, the smallest of these primes is 10102323454577.

The largest is 98987676505033.

Seemed natural to work in base 7 instead, but of course odd bases are no good. In base 8, there are 1057 solutions, all of which use the digit 0. So, 10 is the first base where there’s a sonnet prime that doesn’t include a 0 digit (and in fact there are 6367 of those.

Still obsessed with base 7. All the sonnet numbers are multiples of 6 there, but 204 of them are of the form 6 times a prime.

Hey John — here’s a real he-man prime challenge:

Find a non-trivial pattern (p1, p2, … pn) such that the size of the set of primes with that pattern is itself a member of the set!

I bet this is impossible without allowing leading zeros to be part of the pattern — since I seem to recall that the total number of primes with N digits is not between 10^(N-1) and (10^N)-1.