Finding Programs in the Primes
Lenguage, M = ∞

All of the programs start at the beginning of the string. The following poorly written Python program calculates how many characters are needed for a given M.

def program_length(n):
    PLUS, MINUS, DOT = '000', '001', '100'
    i = 1
    s = ''
    while n &gt; 0:
        i += 1
        if all(i%f for f in range(2,i)): 
            s += str(i) + '\n'
            n -= 1
    out = '110111'
    ch = 0
    for c in s:
        dif = ord(c) - ch
        if dif &gt; 0: out += PLUS * dif
        else: out += MINUS * -dif
        out += DOT
        ch = ord(c)
    return int(out, 2)


For example, for M = 5, the program is the first 2458595061728800486379873255763299470031450306332287344758771914371767127738856987726323081746207100511846413417615836995266879023298634729597739072625027450872641123623948113460334798483696686473335593598924642330139401455349473945729379748942060643508071340354553446024108199659348217846094898762753583206697609445347611002385321978831186831089882700897165873209445730704069057276108988230177356 characters.