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