Saturday 6 April 2024

Primes and Nines + Primes to Apocalyptic Primes

My diurnal age today is 27397 and this number is prime, marking the end of a 30 day drought of primes according to this daily reckoning. The previous prime, 27367, has a property that marks it for membership in OEIS A124596: primes \(p\) such that \(q-p = 30\), where \(q\) is the next prime after \(p\). So here we are at \(q=27397\).

Now this current prime is rather special because it has a property that marks it for membership in OEIS A215421:


 A215421

Primes that remain prime when a single digit 9 is inserted between any two consecutive digits or as the leading or trailing digit.


This means that 927397, 297397, 279397, 273997, 273997 and 273979 are all prime. There is a redundancy in this list of course between 273997 and 273997. Up to 40000, the primes in this sequence are:

7, 19, 37, 41, 199, 239, 311, 587, 661, 941, 967, 1009, 1997, 4993, 4999, 5393, 5651, 6911, 9109, 9397, 9679, 9829, 19417, 20233, 22549, 27397, 29389, 31387, 39989

Clearly, it's been a long while since I experienced a prime with this property and it will be a long while before I experience another. However, what this post is mainly about is how Google's Gemini assisted me in creating an algorithm to generate the initial numbers in this sequence.

I asked Gemini the following question (link):
Can you create a Python program that will generate as output the digit 9 inserted only once, but successively, between every digit of a number that is input. The insertion should take place at the beginning of the number and at the end of the number as well as the between all the digits. For example, if the number 783 was the input then the output would be 9783, 7983, 7893 and 7839.

To which the response was:

Absolutely, here's a Python program that achieves what you described:

This code defines a function insert_digit that takes an integer as input. Here's how it works:

This was very helpful and I was quickly able to incorporate the code into SageMathCell and generate the sequence (permalink). Without the comments, the Python code boils down to this:

def insert_digit(number):
    number_str = str(number)
    inserted_numbers = []
    for i in range(len(number_str) + 1):
        inserted_numbers.append("".join([number_str[:i], "9", number_str[i:]]))
    return inserted_numbers

I find manipulating strings in Python to be quite tedious so I welcomed Gemini doing it for me and the resulting code is straightforward and easy to understand. It can be modified of course using the digits "1", "3" and "7". This generates three new sequences:


 A069246

Primes which yield a prime whenever a 1 is inserted anywhere in them (including at the beginning or end).



Up to 40000, the initial members of this sequence are (permalink):

3, 7, 13, 31, 103, 109, 151, 181, 193, 367, 571, 601, 613, 811, 1117, 1831, 4519, 6871, 11119, 11317, 11467, 13171, 16141, 17167, 18211, 18457, 27241, 38917


A215419





Primes that remain prime when a single digit 3 is inserted between any two consecutive digits or as the leading or trailing digit.

Up to 40000, the initial members of this sequence are (permalink):

7, 11, 17, 31, 37, 73, 271, 331, 359, 373, 673, 733, 1033, 2297, 3119, 3461, 3923, 5323, 5381, 5419, 6073, 6353, 9103, 9887, 18289, 23549, 25349, 31333, 32933, 33349, 35747, 37339, 37361, 37489


 A215420

Primes that remain prime when a single digit 7 is inserted between any two consecutive digits or as the leading or trailing digit.



Up to 40000, the initial members of this sequence are (permalink):

3, 19, 97, 433, 487, 541, 691, 757, 853, 1471, 2617, 2953, 4507, 6481, 7351, 7417, 8317, 13177, 31957

Once I spotted the 27241 in OEIS A069246 it occurred to me that I'd probably covered the insertion of 1's in an earlier post and it turned out that indeed I had. On November 2nd 2023, I created a post titled "The Everyone Prime". In that post, I deal with the insertion of 3's and 7's as well but for some reason neglected to mention the insertion of 9's. 

I made 62 posts since that November post so it's not surprising that I sometimes repeat myself but, even though there's redundancy in the two posts, there is some new material including OEIS A215421 (the insertion of 9's) and the use of Google' Gemini to generate Python code.

As a means of adding additional new content to this post, let's use the previous Python code and try inserting the number of the beast, 666, at the beginning of a prime or between the digits of the prime to create a new prime that might called an apocalyptic prime. We'll only look at starting primes in the range from 1 to 999 so that our resulting apocalyptic primes are less than one million.

The following primes (shown with repetition) produce one, two or three apocalyptic primes (runs of three are marked in bold):

11, 17, 29, 29, 43, 43, 53, 53, 83, 97, 97, 101, 101, 103, 103, 109, 109, 109, 113, 113, 127, 131, 139, 149, 157, 167, 167, 167, 173, 179, 191, 191, 193, 193, 211, 223, 229, 229, 233, 233, 241, 241, 251, 263, 263, 269, 271, 277, 277, 281, 283, 293, 307, 311, 313, 331, 337, 347, 349, 353, 353, 383, 397, 397, 401, 419, 421, 431, 433, 439, 449, 461, 467, 487, 499, 503, 541, 541, 557, 577, 587, 593, 593, 599, 599, 607, 607, 619, 643, 643, 647, 647, 683, 683, 701, 709, 709, 727, 733, 739, 751, 751, 757, 769, 773, 787, 811, 821, 823, 823, 823, 827, 829, 829, 829, 839, 853, 857, 883, 883, 887, 919, 929, 929, 937, 937, 941, 947, 953, 977, 983

Here are the 125 apocalyptic primes that they produce (permalink).

16661, 26669, 46663, 56663, 66617, 66629, 66643, 66653, 66683, 66697, 96667, 106661, 106663, 106669, 116663, 146669, 166601, 166603, 166609, 166613, 166627, 166631, 166657, 166667, 166679, 166693, 196661, 196663, 216661, 226663, 226669, 246661, 256661, 266633, 266641, 266663, 266671, 266677, 266681, 266683, 296663, 316661, 316663, 336667, 346667, 346669, 356663, 366607, 366631, 366683, 366697, 396667, 406661, 426661, 466619, 466649, 486667, 496669, 506663, 546661, 566677, 566693, 586667, 596663, 596669, 616669, 666109, 666139, 666167, 666173, 666191, 666229, 666233, 666269, 666277, 666353, 666431, 666433, 666439, 666461, 666467, 666541, 666557, 666599, 666607, 666643, 666647, 666683, 666727, 666733, 666751, 666769, 666773, 666811, 666821, 666823, 666829, 666857, 666929, 666937, 666983, 706661, 706669, 756667, 766609, 766639, 766651, 766687, 826663, 826667, 826669, 866623, 866629, 866639, 866653, 866683, 886663, 886667, 926669, 936667, 946661, 946667, 966619, 966653, 966677

It can be noted that 607, 643 and 683 produce apocalyptic primes that contain four consecutive sixes, namely 666607, 666643, 666647 and 666683 respectively. Of course, these are not the only apocalyptic primes because those above were generated using initial primes. If we begin with either composite or prime numbers between 1 and 999, then 203 apocalyptic primes are generated (permalink). So 78 composite numbers will also generate these types of primes, beginning with 1 --> 6661 and ending with 979 --> 976669 (neither 1 nor 979 = 11 x 89 are prime). The algorithm is easily modified to accommodate other digit sequences like 777 (permalink).

No comments:

Post a Comment