Created
November 5, 2014 19:09
-
-
Save justinokamoto/7052c29d59291ae7fd9a to your computer and use it in GitHub Desktop.
FOR ROY: List of possible semiprime house numbers (between 5579 and 10000), where both prime factors are equal distant from their neighbors, by a distance of 2 and 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class Address_Primes { | |
private static ArrayList<Integer> possibilities = new ArrayList<Integer>(); | |
private static int minimum = 5579; //Roy's address is bigger than 5579 | |
public static boolean is_prime(int x){ | |
for (int i = 2; i <= (Math.sqrt(x));i++){ | |
if (x % i == 0){ | |
return false; | |
} | |
} | |
return true; | |
} | |
public static boolean equidistant_2(int x){ | |
if (is_prime(x - 1) || is_prime(x + 1)) | |
return false; | |
if (is_prime(x - 2) && is_prime(x + 2)) | |
return true; | |
return false; | |
} | |
public static boolean equidistant_6(int x) { | |
for (int i = 1; i < 6; i++) { | |
if (is_prime(x - i) || is_prime(x + i)) { | |
return false; | |
} | |
} | |
if (is_prime(x - 6) && is_prime(x + 6)) | |
return true; | |
else return false; | |
} | |
public static ArrayList<Integer> enumerate_2(int max){ | |
ArrayList<Integer> equidistant = new ArrayList<Integer>(); | |
for(int i = 2; i < max;i++){ | |
if(is_prime(i) && equidistant_2(i)) | |
equidistant.add(i); | |
} | |
return equidistant; | |
} | |
public static ArrayList<Integer> enumerate_6(int max){ | |
ArrayList<Integer> equidistant = new ArrayList<Integer>(); | |
for(int i = 6; i < max;i++){ | |
if(is_prime(i) && equidistant_6(i)) | |
equidistant.add(i); | |
} | |
return equidistant; | |
} | |
public static ArrayList<Integer> possibilities(int max_2, int max_6){ | |
ArrayList<Integer> equidistant_2 = enumerate_2(max_2); | |
ArrayList<Integer> equidistant_6 = enumerate_6(max_6); | |
for(int i = 0; i < equidistant_2.size();i++) | |
for(int j = 0; j < equidistant_6.size();j++) | |
if((equidistant_2.get(i) * equidistant_6.get(j)) > minimum && (equidistant_2.get(i) * equidistant_6.get(j)) < 10000) | |
Address_Primes.possibilities.add(equidistant_2.get(i) * equidistant_6.get(j)); | |
quicksort(0,Address_Primes.possibilities.size() - 1); | |
return Address_Primes.possibilities; | |
} | |
public static String toString(ArrayList<Integer> arr_list){ | |
int size = arr_list.size(); | |
String re_string = "{ "; | |
for (int i = 0; i < size - 1;i++){ | |
re_string = re_string + arr_list.get(i) + " , "; | |
} | |
re_string = re_string + arr_list.get(size - 1) + " }"; | |
return re_string; | |
} | |
public static void exchange(int i, int j){ | |
int t=Address_Primes.possibilities.get(i); | |
Address_Primes.possibilities.set(i, Address_Primes.possibilities.get(j)); | |
Address_Primes.possibilities.set(j, t); | |
} | |
private static void quicksort(int low, int high) { | |
int i = low, j = high; | |
int pivot = Address_Primes.possibilities.get((high+low)/2); | |
while (i <= j) { | |
while (Address_Primes.possibilities.get(i) < pivot) { | |
i++; | |
} | |
while (Address_Primes.possibilities.get(j) > pivot) { | |
j--; | |
} | |
if (i < j) { | |
exchange(i, j); | |
i++; | |
j--; | |
} else if (i == j) { i++; j--; } | |
} | |
if (low < j) | |
quicksort(low, j); | |
if (i < high) | |
quicksort(i, high); | |
} | |
public static void main(String[] args) { | |
System.out.println(toString(possibilities(10000,10000))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Possible 4-digit house numbers greater than 5579: { 5615 , 5935 , 6115 , 6115 , 8735 , 8765 , 9535 }