diff --git a/src/main/java/mattrixwv/ProjectEuler/Benchmark.java b/src/main/java/mattrixwv/ProjectEuler/Benchmark.java index 4a4313e..7b1c81f 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Benchmark.java +++ b/src/main/java/mattrixwv/ProjectEuler/Benchmark.java @@ -2,7 +2,7 @@ //Matthew Ellison // Created: 07-08-20 //Modified: 07-09-20 -//This is the driver function for the Java version of the ProjectEuler project +//This runs the benchmark functions for the Java version of the ProjectEuler project /* Copyright (C) 2020 Matthew Ellison @@ -159,7 +159,7 @@ public class Benchmark{ numOfTimesToRun = input.nextInt(); while(numOfTimesToRun < 1){ System.out.println("That is an invalid number!"); - System.out.println("How many times do you want to run this problem? "); + System.out.print("How many times do you want to run this problem? "); numOfTimesToRun = input.nextInt(); } return numOfTimesToRun; diff --git a/src/main/java/mattrixwv/ProjectEuler/ProblemSelection.java b/src/main/java/mattrixwv/ProjectEuler/ProblemSelection.java index 693e59b..dfc039a 100644 --- a/src/main/java/mattrixwv/ProjectEuler/ProblemSelection.java +++ b/src/main/java/mattrixwv/ProjectEuler/ProblemSelection.java @@ -2,7 +2,7 @@ //Matthew Ellison // Created: 07-08-20 //Modified: 07-09-20 -//This is the driver function for the Java version of the ProjectEuler project +//This class holds all of the functions needed to handle a problem /* Copyright (C) 2020 Matthew Ellison diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java index e923e09..fb7d14f 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java //Matthew Ellison // Created: 03-01-19 -//Modified: 07-17-20 +//Modified: 08-23-20 //The sum of the even Fibonacci numbers less than 4,000,000 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -66,11 +66,11 @@ public class Problem2 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The sum of all even fibonacci numbers <= %d is %d\n", TOP_NUM, fullSum); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The sum of all even fibonacci numbers <= %d is %d", TOP_NUM, fullSum); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java index b2e4d79..924fb10 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java //Matthew Ellison // Created: 03-01-19 -//Modified: 07-17-20 +//Modified: 08-23-20 //The largest prime factor of 600851475143 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -36,6 +36,7 @@ public class Problem3 extends Problem{ //Instance variables private ArrayList factors; //Holds the factors of goalNumber + //Functions //Constructor public Problem3(){ super("What is the largest prime factor of 600851475143?"); @@ -59,11 +60,11 @@ public class Problem3 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The largest factor of the number %d is %d\n", GOAL_NUMBER, factors.get(factors.size() - 1)); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The largest factor of the number %d is %d", GOAL_NUMBER, factors.get(factors.size() - 1)); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java index 8631457..a6d70d5 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java //Matthew Ellison // Created: 03-01-19 -//Modified: 07-17-20 +//Modified: 08-23-20 //Find the largest palindrome made from the product of two 3-digit numbers //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -78,11 +78,11 @@ public class Problem4 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The largest palindrome is %d\n", palindromes.get(palindromes.size() - 1)); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The largest palindrome is %d", palindromes.get(palindromes.size() - 1)); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java index 640f412..25249f1 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java //Matthew Ellison // Created: 03-01-19 -//Modified: 07-17-20 +//Modified: 08-23-20 //What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -71,11 +71,11 @@ public class Problem5 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The smallest positive number evenly divisibly by all number 1-20 is " + currentNum); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The smallest positive number evenly divisible by all numbers 1-20 is " + currentNum); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java index de214bd..ddab68f 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java //Matthew Ellison // Created: 03-01-19 -//Modified: 07-18-20 +//Modified: 08-23-20 //Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -62,11 +62,11 @@ public class Problem6 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is %d\n", Math.abs(sumOfSquares - squareOfSum)); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is %d", Math.abs(sumOfSquares - squareOfSum)); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java index 7ddf875..4cbead3 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java //Matthew Ellison // Created: 03-01-19 -//Modified: 07-18-20 +//Modified: 08-23-20 //What is the 10001th prime number? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -59,11 +59,11 @@ public class Problem7 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The " + NUMBER_OF_PRIMES + "th prime number is " + primes.get(primes.size() - 1)); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The " + NUMBER_OF_PRIMES + "th prime number is " + primes.get(primes.size() - 1)); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java index 8507f26..17434da 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java //Matthew Ellison // Created: 03-28-19 -//Modified: 07-18-20 +//Modified: 08-23-20 //Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? /* 73167176531330624919225119674426574742355349194934 @@ -87,11 +87,11 @@ public class Problem8 extends Problem{ //Stop the timer timer.stop(); - //Save the results - result = String.format("The greatest product is " + maxProduct + "\nThe numbers are " + maxNums); - //Throw a flag to show the problem is solved solved = true; + + //Save the results + result = String.format("The greatest product is " + maxProduct + "\nThe numbers are " + maxNums); } //Reset the problem so it can be run again public void reset(){ diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java index deb4947..bbfb408 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java @@ -55,12 +55,12 @@ public class Problem9 extends Problem{ //Loop through all possible a's while((a < 1000) && !found){ b = a + 1; //b must be larger than a - c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); //Compute the hyp + c = Math.sqrt((a * a) + (b * b)); //Compute the hyp //Loop through all possible b's for this a while((a + b + c) < 1000){ ++b; - c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); + c = Math.sqrt((a * a) + (b * b)); } //If the sum == 1000 you found the number, otherwise go to the next possible a @@ -75,16 +75,16 @@ public class Problem9 extends Problem{ //Stop the timer timer.stop(); + //Throw a flag to show the problem is solved + solved = true; + //Save the results if(found){ - result = String.format("The Pythagorean triplet is %d + %d + %d\nThe numbers' product is %d\n", a, b, Math.round(c), a * b * Math.round(c)); + result = String.format("The Pythagorean triplet is %d + %d + %d\nThe numbers' product is %d", a, b, Math.round(c), a * b * Math.round(c)); } else{ result = "The number was not found!"; } - - //Throw a flag to show the problem is solved - solved = true; } //Reset the problem so it can be run again public void reset(){