I've written some code for testing Gilbreath's conjecture in python (2.x). The conjecture was shown (in the 90s) to be true up to n=1012. My code uses the primesieve module to quickly generate primes and, by ignoring blocks of 0s and 2s, only calculates values in the array when necessary. However, it's quite slow; it makes heavy use of dictionary lookup, addition and deletion, and I expect would benefit from modification of this aspect.def gilbreath(nMax):    import primesieve    def fill(D, j, k):        if (j, k-1) not in D:            fill(D, j, k-1)        D[(j, k)] = abs(D[(j+1, k-1)]-D[(j, k-1)])        # remove unneeded entries        if (j-1, k) in D:            del D[(j, k-1)]        if (j+1, k) in D:            del D[(j+1, k-1)]    primes = primesieve.Iterator()    D = {}    depthLeft, depth, maxDepth, nDepth = -1, -1, -1, -1    for n in xrange(1, nMax+1):        D[(n, 0)] = int(primes.next_prime())        j, k = n, 0        while (D[(j, k)] > 2) or (k <= depthLeft):            if D[(j, k)] > 2:                depth = k            j -= 1            k += 1            fill(D, j, k)            if (j == 1) and D[(j, k)] > 1:                print conjecture false at n = %d %n        depthLeft = depth        if depth > maxDepth:            maxDepth, nDepth = depth, n    print max depth %d at n = %d of %d %(maxDepth, nDepth, nMax)
Gilbreath's conjecture in Python
python;performance;python 2.7;primes