Updated problem's test times

This commit is contained in:
2020-06-08 11:03:06 -04:00
parent 758fa4714e
commit ad2d14c828
31 changed files with 48 additions and 44 deletions

View File

@@ -44,11 +44,11 @@ public class Problem1 extends Problem{
} }
timer.stop(); timer.stop();
//Save the results //Save the results
result = "The sum of all numbers < " + TOP_NUM.toString() + " is " + sum.toString(); result = "The sum of all numbers < " + TOP_NUM.toString() + 1 + " is " + sum.toString();
} }
} }
/* Results: /* Results:
The sum of all numbers < 1000 is 233168 The sum of all numbers < 1000 is 233168
It took 504.226 microseconds to run this algorithm It took 140.000 microseconds to solve this problem.
*/ */

View File

@@ -49,5 +49,6 @@ public class Problem10 extends Problem{
} }
/* Results: /* Results:
The sum of all the primes < 2000000 is 142913828922
It took 201.347 milliseconds to solve this problem.
*/ */

View File

@@ -189,5 +189,5 @@ public class Problem11 extends Problem{
/* Results: /* Results:
The greatest product of 4 numbers in a line is 70600674 The greatest product of 4 numbers in a line is 70600674
The numbers are [89, 94, 97, 87] The numbers are [89, 94, 97, 87]
It took 2.442 milliseconds to run this algorithm It took 1.310 milliseconds to solve this problem.
*/ */

View File

@@ -69,5 +69,5 @@ public class Problem12 extends Problem{
/* Results: /* Results:
The triangulare number 76576500 is the sum of all numbers >= 12375 and has 576 divisors The triangulare number 76576500 is the sum of all numbers >= 12375 and has 576 divisors
It took 758.987 milliseconds to run this algorithms It took 373.274 milliseconds to solve this problem.
*/ */

View File

@@ -257,5 +257,5 @@ public class Problem13 extends Problem{
/* Results: /* Results:
The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672 The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672
The first 10 digits of the sum of the numbers is 5537376230 The first 10 digits of the sum of the numbers is 5537376230
It took 3.185 milliseconds to run this algorithms It took 919.500 microseconds to solve this problem.
*/ */

View File

@@ -61,7 +61,7 @@ public class Problem14 extends Problem{
result = String.format("The number %d produced a chain of %d steps\n", maxNum, maxLength); result = String.format("The number %d produced a chain of %d steps\n", maxNum, maxLength);
} }
//This function follows the rules of the sequence and returns its length //This function follows the rules of the sequence and returns its length
private static Long checkSeries(Long num){ private Long checkSeries(Long num){
Long length = 1L; //Start at 1 becuase you need to count the starting number Long length = 1L; //Start at 1 becuase you need to count the starting number
//Follow the series, adding 1 for each step you take //Follow the series, adding 1 for each step you take
@@ -82,5 +82,5 @@ public class Problem14 extends Problem{
/* Results: /* Results:
The number 837799 produced a chain of 525 steps The number 837799 produced a chain of 525 steps
It took 1.006 seconds to run this algorithm It took 919.500 microseconds to solve this problem.
*/ */

View File

@@ -33,7 +33,7 @@ public class Problem15 extends Problem{
private Long numOfRoutes = 0L; private Long numOfRoutes = 0L;
public Problem15(){ public Problem15(){
super("How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?"); super("How many routes from the top left corner to the bottom right corner are there through a 20x20 grid if you can only move right and down?");
} }
public void solve(){ public void solve(){
//Setup the rest of the variables //Setup the rest of the variables
@@ -75,5 +75,6 @@ public class Problem15 extends Problem{
} }
/* Results: /* Results:
The number of routes is 137846528820
It took 26.396 minutes to solve this problem.
*/ */

View File

@@ -65,5 +65,5 @@ public class Problem16 extends Problem{
/* Results: /* Results:
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
The sum of the elements is 1366 The sum of the elements is 1366
It took 1.104 milliseconds to run this algorithm It took 411.699 microseconds to solve this problem.
*/ */

View File

@@ -207,5 +207,5 @@ public class Problem17 extends Problem{
/* Results: /* Results:
The sum of all the letters in all the numbers 1-1000 is 21124 The sum of all the letters in all the numbers 1-1000 is 21124
It took 4.862 milliseconds to run this algorithm It took 4.367 milliseconds to solve this problem.
*/ */

View File

@@ -161,5 +161,5 @@ public class Problem18 extends Problem{
/* Results: /* Results:
The value of the longest path is 1074 The value of the longest path is 1074
It took 5.146 milliseconds to run this algorithm It took 1.585 milliseconds to solve this problem.
*/ */

View File

@@ -172,5 +172,5 @@ public class Problem19 extends Problem{
/* Results: /* Results:
There are 171 Sundays that landed on the first of the months from 1901 to 2000 There are 171 Sundays that landed on the first of the months from 1901 to 2000
It took 67.638 milliseconds to run this algorithms It took 46.394 milliseconds to solve this problem.
*/ */

View File

@@ -57,5 +57,5 @@ public class Problem2 extends Problem{
/* Results: /* Results:
The sum of all even fibonacci numbers <= 3999999 is 4613732 The sum of all even fibonacci numbers <= 3999999 is 4613732
It took 940.825 microseconds to run this algorithm It took 551.500 microseconds to solve this problem.
*/ */

View File

@@ -28,7 +28,7 @@ import java.math.BigInteger;
public class Problem20 extends Problem{ public class Problem20 extends Problem{
//The largest number that will be multiplied //The largest number that will be multiplied
private static Integer TOP_NUM = 100; private static final Integer TOP_NUM = 100;
public Problem20(){ public Problem20(){
super("What is the sum of the digits of 100!?"); super("What is the sum of the digits of 100!?");
@@ -65,5 +65,5 @@ public class Problem20 extends Problem{
/* Restuls: /* Restuls:
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
The sum of the digits is: 648 The sum of the digits is: 648
It took 2.667 milliseconds to run this algorithm It took 375.798 microseconds to solve this problem.
*/ */

View File

@@ -86,7 +86,7 @@ public class Problem21 extends Problem{
for(int cnt = 0;cnt < amicable.size();++cnt){ for(int cnt = 0;cnt < amicable.size();++cnt){
result += amicable.get(cnt).toString() + "\n"; result += amicable.get(cnt).toString() + "\n";
} }
result = String.format("The sum of all of these amicable numbers is %d\n", Algorithms.getSum(amicable)); result += String.format("The sum of all of these amicable numbers is %d\n", Algorithms.getSum(amicable));
} }
} }
@@ -103,5 +103,5 @@ All amicable numbers less than 10000 are
6232 6232
6368 6368
The sum of all of these amicable numbers is 31626 The sum of all of these amicable numbers is 31626
It took 27.645 milliseconds to run this algorithm It took 23.551 milliseconds to solve this problem.
*/ */

View File

@@ -30,7 +30,7 @@ import java.util.Collections;
public class Problem22 extends Problem{ public class Problem22 extends Problem{
private static ArrayList<String> names = new ArrayList<String>(Arrays.asList("MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN", private static final ArrayList<String> names = new ArrayList<String>(Arrays.asList("MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN",
"BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE","LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY", "BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE","LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY",
"CYNTHIA","ANGELA","MELISSA","BRENDA","AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE", "CYNTHIA","ANGELA","MELISSA","BRENDA","AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE",
"CAROLYN","CHRISTINE","MARIE","JANET","CATHERINE","FRANCES","ANN","JOYCE","DIANE","ALICE","JULIE","HEATHER","TERESA","DORIS", "CAROLYN","CHRISTINE","MARIE","JANET","CATHERINE","FRANCES","ANN","JOYCE","DIANE","ALICE","JULIE","HEATHER","TERESA","DORIS",
@@ -436,5 +436,5 @@ public class Problem22 extends Problem{
/* Results: /* Results:
The answer to the question is 871198282 The answer to the question is 871198282
It took 14.675 milliseconds to run this algorithm It took 17.822 milliseconds to solve this problem.
*/ */

View File

@@ -80,7 +80,7 @@ public class Problem23 extends Problem{
result = String.format("The answer is %d\n", sum); result = String.format("The answer is %d\n", sum);
} }
//A function that returns true if num can be created by adding two elements from abund and false if it cannot //A function that returns true if num can be created by adding two elements from abund and false if it cannot
private static Boolean isSum(final ArrayList<Integer> abund, Integer num){ private Boolean isSum(final ArrayList<Integer> abund, Integer num){
Integer sum = 0; Integer sum = 0;
//Pick a number for the first part of the sum //Pick a number for the first part of the sum
for(Integer firstNum = 0;firstNum < abund.size();++firstNum){ for(Integer firstNum = 0;firstNum < abund.size();++firstNum){
@@ -102,5 +102,5 @@ public class Problem23 extends Problem{
/* Results: /* Results:
The answer is 4179871 The answer is 4179871
It took 75.846 seconds to run this algorithm It took 49.791 seconds to solve this problem.
*/ */

View File

@@ -55,5 +55,5 @@ public class Problem24 extends Problem{
/* Results /* Results
The 1 millionth permutation is 2783915460 The 1 millionth permutation is 2783915460
It took 1.503 seconds to run this algorithm It took 1.844 seconds to solve this problem.
*/ */

View File

@@ -60,5 +60,5 @@ public class Problem25 extends Problem{
/* Results: /* Results:
The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816 The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
Its index is 4782 Its index is 4782
It took 1.182 seconds to run this algorithm It took 1.051 seconds to solve this problem.
*/ */

View File

@@ -93,5 +93,5 @@ public class Problem26 extends Problem{
/* Results: /* Results:
The longest cycle is 982 digits long The longest cycle is 982 digits long
It started with the number 983 It started with the number 983
It took 41.482 milliseconds to run this algorithm It took 28.969 milliseconds to solve this problem.
*/ */

View File

@@ -30,13 +30,13 @@ import java.util.ArrayList;
public class Problem27 extends Problem{ public class Problem27 extends Problem{
//The A for the most n's generated //The A for the most n's generated
private static Integer topA = 0; private Integer topA = 0;
//The B for the most n's generated //The B for the most n's generated
private static Integer topB = 0; private Integer topB = 0;
//The most n's generated //The most n's generated
private static Integer topN = 0; private Integer topN = 0;
//A list of all primes that could possibly be generated with this formula //A list of all primes that could possibly be generated with this formula
private static ArrayList<Integer> primes = Algorithms.getPrimes(12000); private ArrayList<Integer> primes = Algorithms.getPrimes(12000);
public Problem27(){ public Problem27(){
super("Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0"); super("Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0");
@@ -79,5 +79,5 @@ public class Problem27 extends Problem{
The greatest number of primes found is 70 The greatest number of primes found is 70
It was found with A = -61, B = 971 It was found with A = -61, B = 971
The product of A and B is -59231 The product of A and B is -59231
It took 4.765 seconds to run this algorithm It took 4.772 seconds to solve this problem.
*/ */

View File

@@ -30,7 +30,7 @@ public class Problem28 extends Problem{
//Holds the grid that we will be filling and searching //Holds the grid that we will be filling and searching
private static ArrayList<ArrayList<Integer>> grid; private static ArrayList<ArrayList<Integer>> grid;
//Holds the sum of the diagonals of the grid //Holds the sum of the diagonals of the grid
private static Integer sumOfDiagonals = 0; private Integer sumOfDiagonals = 0;
public Problem28(){ public Problem28(){
super("What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral"); super("What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral");
@@ -127,5 +127,5 @@ public class Problem28 extends Problem{
/* Results: /* Results:
The sum of the diagonals in the given grid is 669171001 The sum of the diagonals in the given grid is 669171001
It took 158.348 milliseconds to run this algorithm It took 84.535 milliseconds to solve this problem.
*/ */

View File

@@ -37,7 +37,7 @@ public class Problem29 extends Problem{
//The highest possible value for b //The highest possible value for b
private static final Integer TOP_B = 100; private static final Integer TOP_B = 100;
//Holds all unique values generated //Holds all unique values generated
private static ArrayList<BigInteger> unique; private ArrayList<BigInteger> unique;
public Problem29(){ public Problem29(){
super("How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?"); super("How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?");
@@ -72,5 +72,5 @@ public class Problem29 extends Problem{
/* Results: /* Results:
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183 The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
It took 258.922 milliseconds to run this algorithm It took 125.133 milliseconds to solve this problem.
*/ */

View File

@@ -54,5 +54,5 @@ public class Problem3 extends Problem{
/* Results: /* Results:
The largest factor of the number 600851475143 is 6857 The largest factor of the number 600851475143 is 6857
It took 674.398 milliseconds to run this algorithm It took 337.600 milliseconds to solve this problem.
*/ */

View File

@@ -93,5 +93,5 @@ public class Problem30 extends Problem{
/* Results: /* Results:
The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839 The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839
It took 478.387 milliseconds to run this algorithm It took 307.629 milliseconds to solve this problem.
*/ */

View File

@@ -74,5 +74,5 @@ public class Problem4 extends Problem{
/* Results: /* Results:
The largest palindrome is 906609 The largest palindrome is 906609
It took 105.376 milliseconds to run this algorithm It took 47.490 milliseconds to solve this problem.
*/ */

View File

@@ -61,5 +61,5 @@ public class Problem5 extends Problem{
/* Results: /* Results:
The smallest positive number evenly divisibly by all number 1-20 is 232792560 The smallest positive number evenly divisibly by all number 1-20 is 232792560
It took 1.987 seconds to run this algorithm It took 393.616 milliseconds to solve this problem.
*/ */

View File

@@ -58,5 +58,5 @@ public class Problem6 extends Problem{
/* Results: /* Results:
The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150 The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150
It took 466.115 microseconds to run this algorithm It took 51.999 microseconds to solve this problem.
*/ */

View File

@@ -334,5 +334,5 @@ public class Problem67 extends Problem{
/* Results: /* Results:
The value of the longest path is 7273 The value of the longest path is 7273
It took 3.736 seconds to run this algorithm It took 0.000 nanoseconds to solve this problem.
*/ */

View File

@@ -53,5 +53,5 @@ public class Problem7 extends Problem{
/* Results: /* Results:
The 10001th prime number is 104743 The 10001th prime number is 104743
It took 142.783 milliseconds to run this algorithm It took 43.496 milliseconds to solve this problem.
*/ */

View File

@@ -82,5 +82,5 @@ public class Problem8 extends Problem{
/* Results: /* Results:
The greatest product is 23514624000 The greatest product is 23514624000
The numbers are 5576689664895 The numbers are 5576689664895
It took 8.069 milliseconds to run this algorithm It took 2.901 milliseconds to solve this problem.
*/ */

View File

@@ -71,5 +71,7 @@ public class Problem9 extends Problem{
} }
/* Results: /* Results:
The Pythagorean triplet is 200 + 375 + 425
The numbers' product is 31875000
It took 12.971 milliseconds to solve this problem.
*/ */