Updated problem 27 algorithm

This commit is contained in:
2020-10-30 16:19:12 -04:00
parent ebff487b68
commit af89d5619e
2 changed files with 3 additions and 3 deletions

View File

@@ -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;

View File

@@ -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;
} }