mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Updated problem 27 algorithm
This commit is contained in:
@@ -34,7 +34,7 @@ import mattrixwv.exceptions.InvalidResult;
|
|||||||
public class Benchmark{
|
public class Benchmark{
|
||||||
private static final Scanner input = new Scanner(System.in);
|
private static final Scanner input = new Scanner(System.in);
|
||||||
private static enum BenchmarkOptions{runSpecific, runAllShort, runAll, exit, size};
|
private static enum BenchmarkOptions{runSpecific, runAllShort, runAll, exit, size};
|
||||||
private static final ArrayList<Integer> tooLong = new ArrayList<Integer>(Arrays.asList(15, 23, 24, 27));
|
private static final ArrayList<Integer> tooLong = new ArrayList<Integer>(Arrays.asList(15, 23, 24));
|
||||||
//The driver function for the benchmark selection
|
//The driver function for the benchmark selection
|
||||||
public static void benchmarkMenu() throws InvalidResult{
|
public static void benchmarkMenu() throws InvalidResult{
|
||||||
BenchmarkOptions selection = BenchmarkOptions.size;
|
BenchmarkOptions selection = BenchmarkOptions.size;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class Problem27 extends Problem{
|
|||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
//Get the primes
|
//Get the primes
|
||||||
primes = Algorithms.getPrimes(12000);
|
//primes = Algorithms.getPrimes(12000);
|
||||||
|
|
||||||
//Start with the lowest possible A and check all possibilities after that
|
//Start with the lowest possible A and check all possibilities after that
|
||||||
for(int a = -LARGEST_POSSIBLE_A;a <= LARGEST_POSSIBLE_A;++a){
|
for(int a = -LARGEST_POSSIBLE_A;a <= LARGEST_POSSIBLE_A;++a){
|
||||||
@@ -71,7 +71,7 @@ public class Problem27 extends Problem{
|
|||||||
//Start with n=0 and check the formula to see how many primes you can get with concecutive n's
|
//Start with n=0 and check the formula to see how many primes you can get with concecutive n's
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int quadratic = (n * n) + (a * n) + b;
|
int quadratic = (n * n) + (a * n) + b;
|
||||||
while(Algorithms.isFound(primes, quadratic)){
|
while(Algorithms.isPrime(quadratic)){
|
||||||
++n;
|
++n;
|
||||||
quadratic = (n * n) + (a * n) + b;
|
quadratic = (n * n) + (a * n) + b;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user