mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Updated long running problem to test smaller dataset
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user