mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Added new tests
This commit is contained in:
@@ -32,7 +32,7 @@ import com.mattrixwv.NumberAlgorithms;
|
||||
public class Problem35 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
private static final int MAX_NUM = 999999; //The largest number that we are checking for primes
|
||||
protected static int maxNum = 999999; //The largest number that we are checking for primes
|
||||
//Instance variables
|
||||
private List<Integer> primes; //The primes below MAX_NUM
|
||||
private ArrayList<Integer> circularPrimes; //The circular primes below MAX_NUM
|
||||
@@ -49,7 +49,7 @@ public class Problem35 extends Problem{
|
||||
}
|
||||
//Constructor
|
||||
public Problem35(){
|
||||
super("How many circular primes are there below one million?");
|
||||
super(String.format("How many circular primes are there below %d?", maxNum + 1));
|
||||
primes = new ArrayList<>();
|
||||
circularPrimes = new ArrayList<>();
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class Problem35 extends Problem{
|
||||
|
||||
|
||||
//Get all primes under 1,000,000
|
||||
primes = NumberAlgorithms.getPrimes(MAX_NUM);
|
||||
primes = NumberAlgorithms.getPrimes(maxNum);
|
||||
//Go through all primes, get all their rotations, and check if those numbers are also primes
|
||||
for(int prime : primes){
|
||||
boolean allRotationsPrime = true;
|
||||
@@ -103,7 +103,7 @@ public class Problem35 extends Problem{
|
||||
//Returns a string with the solution to the problem
|
||||
public String getResult(){
|
||||
solvedCheck("result");
|
||||
return String.format("The number of all circular prime numbers under %d is %d", MAX_NUM, circularPrimes.size());
|
||||
return String.format("The number of all circular prime numbers under %d is %d", maxNum, circularPrimes.size());
|
||||
}
|
||||
//Returns the ArrayList of primes < MAX_NUM
|
||||
public List<Integer> getPrimes(){
|
||||
|
||||
@@ -32,14 +32,14 @@ import com.mattrixwv.Triple;
|
||||
public class Problem39 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
private static final long MAX_PERIMETER = 1000;
|
||||
protected static long maxPerimeter = 1000;
|
||||
//Instace variables
|
||||
private ArrayList<Triple<Long, Long, Long>> longestSolutions;
|
||||
|
||||
//Functions
|
||||
//Constructor
|
||||
public Problem39(){
|
||||
super("If p is the perimeter of a right triangle for which value of p <= 1000 is the number of solutions for the sides {a, b, c} maximized");
|
||||
super(String.format("If p is the perimeter of a right triangle for which value of p <= %d is the number of solutions for the sides {a, b, c} maximized", maxPerimeter));
|
||||
longestSolutions = new ArrayList<>();
|
||||
}
|
||||
//Operational functions
|
||||
@@ -58,7 +58,7 @@ public class Problem39 extends Problem{
|
||||
|
||||
|
||||
//Loop for perimeter <= 1000
|
||||
for(long perimeter = 1;perimeter <= MAX_PERIMETER;++perimeter){
|
||||
for(long perimeter = 1;perimeter <= maxPerimeter;++perimeter){
|
||||
ArrayList<Triple<Long, Long, Long>> solutions = new ArrayList<>();
|
||||
for(long a = 1;(a * 3) <= perimeter;++a){
|
||||
for(long b = a;(a + b + b) <= perimeter;++b){
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Problem40 extends Problem{
|
||||
return String.format("The product is %d", product);
|
||||
}
|
||||
//Returns the string of the decimal
|
||||
public String irrationalDecimal(){
|
||||
public String getIrrationalDecimal(){
|
||||
solvedCheck("decimal string");
|
||||
return "0." + irrationalDecimal.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user