The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.

What 12-digit number do you form by concatenating the three terms in this sequence?

Sage Solution

There are really only a handful of ways to go about this, and the timing isn’t going to be too substantial. So, I’m simply going to write an in-line Sage code block and execute it. The idea is to get a list of primes between 1,000 and 10,000, sort their digit decompositions, and then (after seeing which primes have the same digit decompositions), see which prime subsets have an arithmetic sequence underlying the distances between them. No too horribly interesting, but the code below does the job.

import time
start = time.time()
# make a list of primes
P = prime_range(1000,10000)
# for each prime, make a list of digits, and sort that list
L = [p.digits() for p in P]
for i in range(len(L)):
# make a list of digits that appear for at least 3 primes
M = []
for i in range(len(L)-3):
    if L[i]==L[i+1] and L[i+1]==L[i+2] and L[i+2]==L[i+3]:
        if L[i] not in M: M.append(L[i])
# N is a list of lists of at least 3 primes with the same 4 digits
N = []
for m in M:
for p in P:
    s = p.digits()
    if s in M:
        r = M.index(s)
# Use a Sage combinations iterator to examine sets of 3 primes
for n in N:
    X = combinations_iterator(n, 3)
    for x in X:
        if x[1]-x[0] == x[2]-x[1]: print x
elapsed = time.time() - start
print "time elapsed: %s seconds" % elapsed

When executed, we get the following result.

[1487, 4817, 8147]
[2969, 6299, 9629]
time elapsed: 0.0485339164734 seconds


  1. Posted May 28, 2015 at 08:38 | Permalink

    Very good site you have here but I was wanting to know if you knew of any forums that cover the same topics discussed in this article? I’d really love to be a part of group where I can get comments from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Kudos!

  2. Posted October 10, 2015 at 05:37 | Permalink

    I really like what you guys tend to be up too. This sort of clever work and coverage! Keep up the very good works guys I’ve you guys to blogroll.

  3. Martin Stoufer
    Posted May 16, 2016 at 13:08 | Permalink

    I implemented this algorightm in Obj C. and found that your final equality test found another valid triplet: {2713, 3217,3721}. You may want to just check against the value of 3330.

  4. Posted July 27, 2016 at 12:31 | Permalink

    Have sent it to my mother and father. An incredibly practical article!
    I am confident it will probably be ideal for everyone!

  5. Posted July 28, 2016 at 13:24 | Permalink

    Ellis Park Stadium & Soccer City, Johannesburg (Gauteng).
    Through the course of time, Mexico has gained a single FIFA under 17
    World Cup, a single FIFA Confederations Cup, three CONCACAF Championships, four CONCACAF Gold Cups, three NAFC
    Championships, and three Pan Am Games Gold Medals. The difference is that the outer casing has been significantly altered, with the controversial “chin” that is
    present on the Asian, Canadian and European models being removed in lieu of a smooth, beveled surface where all but two of
    the once raised buttons now lie flat.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">