Project Euler – Problem 51

Problem 51:
By replacing the 1st digit of *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.

By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property.

Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family.

import java.util.HashSet;

class runner
{
	/* 
	 * Sieve to determine composite/prime numbers
	 * My attempt at optimizing mainly is made up of checking values of 
	 *    n*n, n*n+2*n, .. length 
	 * This reduces the execution time for arr.length=1mil from 30ms to 16ms.
	 */
	private static int sieveArray(boolean[] arr){
		arr[0]=true;arr[1]=true;
		int c=2;
		for(int j = 4; j < arr.length; j+=2){
			arr[j] = true;
			c++;
		}
		
		for(int i=3;i convertArr(int n, boolean[] arr2){
		//int[] arr = new int[n];
		HashSet arr = new HashSet();
		//int k=0;
		for(int i=0;i primes = convertArr(numOfPrimes, primesieve);
		System.out.println("convertArr time: "+(System.currentTimeMillis() - time));
		
		primesieve = null;
		System.gc();
		
		int lfamily = 0;
		String lp = "9999999999";
		for(String p: primes){//For Each Prime			
			for(int i=0;i<10;i++){//iterate from 0..9
				int family = 1;
				
				for(int j=1;j<10;j++){//Push 0+1... 0+9 [1..9] 
					char newChar = (char)(48+((i+j)%10));
					
					boolean found = false;
					StringBuffer check = new StringBuffer();
					
					for(int k=0;k lfamily){
					lfamily = family;
					lp=p;
				}else if(family == lfamily){
					if(p.compareTo(lp) < 0){
						lp = p;
					}
				}
			}
		}
		System.out.println("lp:"+lp+" len:"+lfamily);
		System.out.println("time: "+(System.currentTimeMillis() - time));
	}
}