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)): L[i].sort() L.sort()   # 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: N.append([]) for p in P: s = p.digits() s.sort() if s in M: r = M.index(s) N[r].append(p)   # 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 |

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 |

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 |

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 |

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 |

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.

6. Posted October 28, 2017 at 06:19 |

This is a subject close to my heart cheers. Thanks

7. checkio
Posted January 26, 2018 at 14:20 |

Simplified version:

from sympy import isprime
step = 3330
for i in range(1000, 10000-2*step):
a, b, c = i, i+step, i+2*step
if not (set(str(a)) == set(str(b)) == set(str(c))):
continue
if not (isprime(a) and isprime(b) and isprime(c)):
continue
print(a, b, c)