Made all programs similar

This commit is contained in:
2021-07-03 22:34:14 -04:00
parent 290e43173a
commit 541adacbf0

View File

@@ -143,15 +143,16 @@ public class Problem13 extends Problem{
super("Work out the first ten digits of the sum of the one-hundred 50-digit numbers");
nums = new ArrayList<BigInteger>();
reserveVectors();
setNums();
sum = BigInteger.ZERO;
}
//Operational functions
//A function to set the nums vector
private void setNums(){
private void reserveVectors(){
nums.ensureCapacity(100);
}
//Reserve the size of the vector to speed up insertion
private void reserveVectors(){
private void setNums(){
//Setup the array
nums.add(new BigInteger("37107287533902102798797998220837590246510135740250"));
nums.add(new BigInteger("46376937677490009712648124896970078050417018260538"));
@@ -265,9 +266,6 @@ public class Problem13 extends Problem{
//Start the timer
timer.start();
//Setup the array
setNums();
//Get the sum of all the numbers
sum = ArrayAlgorithms.getBigSum(nums);
@@ -286,6 +284,7 @@ public class Problem13 extends Problem{
sum = BigInteger.ZERO;
nums.clear();
reserveVectors();
setNums();
}
//Gets
//Returns the result of solving the problem