mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Finished adding tests
This commit is contained in:
@@ -33,6 +33,8 @@ import com.mattrixwv.StringAlgorithms;
|
||||
|
||||
public class Problem43 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
protected static String nums = "0123456789";
|
||||
//Instance variables
|
||||
private ArrayList<Long> subPrimePandigitals;
|
||||
|
||||
@@ -55,7 +57,7 @@ public class Problem43 extends Problem{
|
||||
|
||||
|
||||
//Get all of the 0-9 pandigitals
|
||||
List<String> pandigitals = StringAlgorithms.getPermutations("0123456789");
|
||||
List<String> pandigitals = StringAlgorithms.getPermutations(nums);
|
||||
//Get all of the primes we need
|
||||
List<Long> primes = NumberAlgorithms.getNumPrimes(7L);
|
||||
//Break them into their component parts and see if they are divisible by the prime numbers
|
||||
|
||||
@@ -111,6 +111,11 @@ public class Problem44 extends Problem{
|
||||
solvedCheck("second pentagonal number");
|
||||
return pentagonalNumber2;
|
||||
}
|
||||
//Returns the difference between the 2 pentagonal numbers
|
||||
public long getDifference(){
|
||||
solvedCheck("difference between the pentagonal numbers");
|
||||
return Math.abs(pentagonalNumber1 - pentagonalNumber2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Results:
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Problem50 extends Problem{
|
||||
//Functions
|
||||
//Constructor
|
||||
public Problem50(){
|
||||
super("Which prime, below one-million, can be written as the sum of the most consecutive primes?");
|
||||
super(String.format("Which prime, below %d, can be written as the sum of the most consecutive primes?", MAX + 1));
|
||||
consecutivePrimes = new ArrayList<>();
|
||||
}
|
||||
//Operational functions
|
||||
@@ -130,7 +130,7 @@ public class Problem50 extends Problem{
|
||||
//Returns a string with the solution to the problem
|
||||
public String getResult(){
|
||||
solvedCheck("results");
|
||||
return String.format("The prime below one-million that can be written as the sum of the most consecutive primes is %d", ArrayAlgorithms.getLongSum(consecutivePrimes));
|
||||
return String.format("The prime below %d that can be written as the sum of the most consecutive primes is %d", MAX + 1, ArrayAlgorithms.getLongSum(consecutivePrimes));
|
||||
}
|
||||
//Returns the list of consecutive primes
|
||||
public List<Long> getConsecutivePrimes(){
|
||||
@@ -147,6 +147,6 @@ public class Problem50 extends Problem{
|
||||
}
|
||||
|
||||
/* Results:
|
||||
The prime below one-million that can be written as the sum of the most consecutive primes is 997651
|
||||
The prime below 1000000 that can be written as the sum of the most consecutive primes is 997651
|
||||
It took an average of 77.425 milliseconds to run this problem through 100 iterations
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user