Updated long running problem to test smaller dataset

This commit is contained in:
2022-12-06 18:41:20 -05:00
parent 5bdb9f8110
commit d48d245110
6 changed files with 50 additions and 37 deletions

View File

@@ -33,7 +33,7 @@ import java.util.List;
public class Problem23 extends Problem{
//Variables
//Static variables
private static final int MAX_NUM = 28123; //The largest number to be checked
protected static int maxNum = 28123; //The largest number to be checked
//Instance variables
private ArrayList<Integer> divisorSums; //This gives the sum of the divisors at subscripts
private long sum; //The sum of all the numbers we are looking for
@@ -49,9 +49,9 @@ public class Problem23 extends Problem{
//Operational functions
//Reserve the size of the array to speed up insertion
private void reserveArray(){
divisorSums.ensureCapacity(MAX_NUM); //It is faster to reserve the appropriate amount of ram now
divisorSums.ensureCapacity(maxNum); //It is faster to reserve the appropriate amount of ram now
//Make sure every element has a 0 in it's location
while(divisorSums.size() <= MAX_NUM){
while(divisorSums.size() <= maxNum){
divisorSums.add(0);
}
}
@@ -68,7 +68,7 @@ public class Problem23 extends Problem{
//Get the sum of the divisors of all numbers < MAX_NUM
for(int cnt = 1;cnt < MAX_NUM;++cnt){
for(int cnt = 1;cnt < maxNum;++cnt){
List<Integer> div = NumberAlgorithms.getDivisors(cnt);
//Remove the last element, which is the number itself. This gives us the propper divisors
if(div.size() > 1){
@@ -86,7 +86,7 @@ public class Problem23 extends Problem{
}
//Check if each number can be the sum of 2 abundant numbers and add to the sum if no
for(int cnt = 1;cnt < MAX_NUM;++cnt){
for(int cnt = 1;cnt < maxNum;++cnt){
if(!isSum(abund, cnt)){
sum += cnt;
}