Project Euler – Problem 49

Problem 49:
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?

``` ```
``````import java.util.Collections;
import java.util.Vector;

class runner
{
public static boolean isPrime(int n){
if(primes.contains(n)) return true;
double limit = Math.sqrt(n);
for(int p: primes){
if(p > limit) break;
if(n % p == 0) return false;
}
return true;
}

//Concept from Steinhausâ€“Johnsonâ€“Trotter
public static void permute(String obj, Vector arr){
if(arr.size() == 0){
return;
}
Vector result = new Vector();

for(String str: arr){
for(int i=0;i primes = new Vector();

public static void main (String[] args) throws java.lang.Exception
{
long time = System.currentTimeMillis();

for(int i=3; i<=9999; i++){
isPrime(i);//populate prime array
}

for(int n : primes){
String cur = ""+n;
if(cur.length() != 4) continue;
Vector permutations = new Vector();
for(int i=0;i permuteAndPrimeSet = new LinkedHashSet();
for(String str : permutations){
int i = Integer.valueOf(str);
if(i/1000 == 0 || i < n) continue;