mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2026-02-03 19:02:28 -05:00
Fixed sonarqube problems
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -27,7 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mattrixwv</groupId>
|
<groupId>mattrixwv</groupId>
|
||||||
<artifactId>myClasses</artifactId>
|
<artifactId>myClasses</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -19,35 +19,37 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler;
|
package com.mattrixwv.project_euler;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import mattrixwv.Stopwatch;
|
import com.mattrixwv.Stopwatch;
|
||||||
import mattrixwv.ProjectEuler.Problems.Problem;
|
import com.mattrixwv.exceptions.InvalidResult;
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
|
||||||
|
import com.mattrixwv.project_euler.problems.Problem;
|
||||||
|
|
||||||
|
|
||||||
public class Benchmark{
|
public class Benchmark{
|
||||||
|
private Benchmark(){}
|
||||||
private static final Scanner input = new Scanner(System.in);
|
private static final Scanner input = new Scanner(System.in);
|
||||||
private static enum BenchmarkOptions{runSpecific, runAllShort, runAll, exit, size};
|
private enum BenchmarkOptions{RUN_SPECIFIC, RUN_ALL_SHORT, RUN_ALL, EXIT, SIZE};
|
||||||
private static final ArrayList<Integer> tooLong = new ArrayList<Integer>(Arrays.asList(15, 23, 24, 35));
|
private static final ArrayList<Integer> tooLong = new ArrayList<>(Arrays.asList(15, 23, 24, 35));
|
||||||
//The driver function for the benchmark selection
|
//The driver function for the benchmark selection
|
||||||
public static void benchmarkMenu() throws InvalidResult{
|
public static void benchmarkMenu() throws InvalidResult{
|
||||||
BenchmarkOptions selection = BenchmarkOptions.size;
|
BenchmarkOptions selection;
|
||||||
|
|
||||||
printMenu();
|
printMenu();
|
||||||
selection = getMenuSelection();
|
selection = getMenuSelection();
|
||||||
|
|
||||||
switch(selection){
|
switch(selection){
|
||||||
case runSpecific : runSpecific(); break;
|
case RUN_SPECIFIC : runSpecific(); break;
|
||||||
case runAllShort : runAllShort(); break;
|
case RUN_ALL_SHORT : runAllShort(); break;
|
||||||
case runAll : runAll(); break;
|
case RUN_ALL : runAll(); break;
|
||||||
case exit : break;
|
case EXIT : break;
|
||||||
case size : break;
|
case SIZE : break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Print the benchmark menu
|
//Print the benchmark menu
|
||||||
@@ -71,7 +73,7 @@ public class Benchmark{
|
|||||||
//Determines if a value is a valid menu option. Helper for getBechmarkMenuSelection
|
//Determines if a value is a valid menu option. Helper for getBechmarkMenuSelection
|
||||||
private static boolean isValidMenu(int selection){
|
private static boolean isValidMenu(int selection){
|
||||||
//Ordinal + 1 because enum starts at 0
|
//Ordinal + 1 because enum starts at 0
|
||||||
if((selection > 0) && (selection < (BenchmarkOptions.size.ordinal() + 1))){
|
if((selection > 0) && (selection < (BenchmarkOptions.SIZE.ordinal() + 1))){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -83,11 +85,11 @@ public class Benchmark{
|
|||||||
BenchmarkOptions sel = null;
|
BenchmarkOptions sel = null;
|
||||||
|
|
||||||
switch(selection){
|
switch(selection){
|
||||||
case 1 : sel = BenchmarkOptions.runSpecific; break;
|
case 1 : sel = BenchmarkOptions.RUN_SPECIFIC; break;
|
||||||
case 2 : sel = BenchmarkOptions.runAllShort; break;
|
case 2 : sel = BenchmarkOptions.RUN_ALL_SHORT; break;
|
||||||
case 3 : sel = BenchmarkOptions.runAll; break;
|
case 3 : sel = BenchmarkOptions.RUN_ALL; break;
|
||||||
case 4 : sel = BenchmarkOptions.exit; break;
|
case 4 : sel = BenchmarkOptions.EXIT; break;
|
||||||
default : sel = BenchmarkOptions.size;
|
default : sel = BenchmarkOptions.SIZE;
|
||||||
}
|
}
|
||||||
return sel;
|
return sel;
|
||||||
}
|
}
|
||||||
@@ -187,7 +189,6 @@ public class Benchmark{
|
|||||||
String timeResults = Stopwatch.getStr(totalTime);
|
String timeResults = Stopwatch.getStr(totalTime);
|
||||||
|
|
||||||
//Tally the results
|
//Tally the results
|
||||||
String results = "\n\n" + problem.getResult() + "\nIt took an average of " + timeResults + " to run this problem through " + timesRun + " iterations\n\n";
|
return "%n%n" + problem.getResult() + "%nIt took an average of " + timeResults + " to run this problem through " + timesRun + " iterations%n%n";
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,22 +19,22 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler;
|
package com.mattrixwv.project_euler;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
import com.mattrixwv.exceptions.InvalidResult;
|
||||||
|
|
||||||
|
|
||||||
public class Driver{
|
public class Driver{
|
||||||
//An enum to hold the possible menu selections
|
//An enum to hold the possible menu selections
|
||||||
private static enum SELECTIONS{SOLVE, DESCRIPTION, LIST, BENCHMARK, EXIT, SIZE};
|
private enum SELECTIONS{SOLVE, DESCRIPTION, LIST, BENCHMARK, EXIT, SIZE};
|
||||||
private static final Scanner input = new Scanner(System.in);
|
private static final Scanner input = new Scanner(System.in);
|
||||||
|
|
||||||
//Drives the program
|
//Drives the program
|
||||||
public static void main(String[] args) throws InvalidResult{
|
public static void main(String[] args) throws InvalidResult{
|
||||||
SELECTIONS selection = SELECTIONS.SIZE; //Holds the menu selection of the user
|
SELECTIONS selection; //Holds the menu selection of the user
|
||||||
do{
|
do{
|
||||||
//Print the menu and prompt the user to select an action
|
//Print the menu and prompt the user to select an action
|
||||||
printMenu();
|
printMenu();
|
||||||
@@ -71,14 +71,9 @@ public class Driver{
|
|||||||
return getSelection(selection);
|
return getSelection(selection);
|
||||||
}
|
}
|
||||||
//Make sure the value passed in is a valid menu option
|
//Make sure the value passed in is a valid menu option
|
||||||
private static Boolean isValidMenu(Integer selection){
|
private static boolean isValidMenu(Integer selection){
|
||||||
//Ordinal + 1 because enum starts at 0
|
//Ordinal + 1 because enum starts at 0
|
||||||
if((selection > 0) && (selection < (SELECTIONS.SIZE.ordinal() + 1))){
|
return ((selection > 0) && (selection < (SELECTIONS.SIZE.ordinal() + 1)));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//Turns an integer passed to it into a SELECTION enum
|
//Turns an integer passed to it into a SELECTION enum
|
||||||
private static SELECTIONS getSelection(Integer selection){
|
private static SELECTIONS getSelection(Integer selection){
|
||||||
@@ -19,21 +19,23 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler;
|
package com.mattrixwv.project_euler;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import mattrixwv.ProjectEuler.Problems.*;
|
import com.mattrixwv.exceptions.InvalidResult;
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
|
||||||
|
import com.mattrixwv.project_euler.problems.*;
|
||||||
|
|
||||||
|
|
||||||
public class ProblemSelection{
|
public class ProblemSelection{
|
||||||
private static final Scanner input = new Scanner(System.in);
|
private static final Scanner input = new Scanner(System.in);
|
||||||
//Holds the valid problem numbers
|
//Holds the valid problem numbers
|
||||||
public static final ArrayList<Integer> PROBLEM_NUMBERS = new ArrayList<Integer>(Arrays.asList( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
public static final List<Integer> PROBLEM_NUMBERS = new ArrayList<>(Arrays.asList( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
||||||
31, 32, 33, 34, 35, 36, 37, 38, 67));
|
31, 32, 33, 34, 35, 36, 37, 38, 67));
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler;
|
package com.mattrixwv.project_euler;
|
||||||
|
|
||||||
|
|
||||||
public class Unsolved extends RuntimeException{
|
public class Unsolved extends RuntimeException{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//This is a base class for problems to use as a template
|
//This is a base class for problems to use as a template
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
@@ -19,12 +19,13 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.Stopwatch;
|
import com.mattrixwv.Stopwatch;
|
||||||
import mattrixwv.ProjectEuler.Unsolved;
|
import com.mattrixwv.exceptions.InvalidResult;
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
|
||||||
|
import com.mattrixwv.project_euler.Unsolved;
|
||||||
|
|
||||||
|
|
||||||
public abstract class Problem{
|
public abstract class Problem{
|
||||||
@@ -35,7 +36,7 @@ public abstract class Problem{
|
|||||||
protected boolean solved; //Shows whether the problem has already been solved
|
protected boolean solved; //Shows whether the problem has already been solved
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
public Problem(String description){
|
protected Problem(String description){
|
||||||
this.description = description;
|
this.description = description;
|
||||||
solved = false;
|
solved = false;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem1.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem1.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem1 extends Problem{
|
public class Problem1 extends Problem{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem10.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem10.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-03-19
|
// Created: 03-03-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the sum of all the primes below two million
|
//Find the sum of all the primes below two million
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,11 +20,11 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem10 extends Problem{
|
public class Problem10 extends Problem{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-03-19
|
// Created: 03-03-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
|
//What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
|
||||||
/*
|
/*
|
||||||
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
|
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -42,12 +42,13 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem11 extends Problem{
|
public class Problem11 extends Problem{
|
||||||
@@ -81,7 +82,7 @@ public class Problem11 extends Problem{
|
|||||||
//Constructor
|
//Constructor
|
||||||
public Problem11(){
|
public Problem11(){
|
||||||
super("What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?");
|
super("What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?");
|
||||||
greatestProduct = new ArrayList<Integer>();
|
greatestProduct = new ArrayList<>();
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
//Solve the problem
|
//Solve the problem
|
||||||
@@ -93,7 +94,7 @@ public class Problem11 extends Problem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Holds the numbers we are currently working on
|
//Holds the numbers we are currently working on
|
||||||
ArrayList<Integer> currentProduct = new ArrayList<Integer>();
|
ArrayList<Integer> currentProduct = new ArrayList<>();
|
||||||
|
|
||||||
//Make sure all elements have at least 4 elements
|
//Make sure all elements have at least 4 elements
|
||||||
for(int cnt = 0;cnt < 4;++cnt){
|
for(int cnt = 0;cnt < 4;++cnt){
|
||||||
@@ -210,10 +211,10 @@ public class Problem11 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The greatest product of 4 numbers in a line is %d\nThe numbers are %s", ArrayAlgorithms.getProd(greatestProduct), greatestProduct.toString());
|
return String.format("The greatest product of 4 numbers in a line is %d%nThe numbers are %s", ArrayAlgorithms.getProd(greatestProduct), greatestProduct.toString());
|
||||||
}
|
}
|
||||||
//Returns the numbers that were being searched
|
//Returns the numbers that were being searched
|
||||||
public ArrayList<Integer> getNumbers(){
|
public List<Integer> getNumbers(){
|
||||||
solvedCheck("numbers");
|
solvedCheck("numbers");
|
||||||
return greatestProduct;
|
return greatestProduct;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem12.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem12.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// Created: 03-04-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//What is the value of the first triangle number to have over five hundred divisors?
|
//What is the value of the first triangle number to have over five hundred divisors?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,13 +20,13 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem12 extends Problem{
|
public class Problem12 extends Problem{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem13.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem13.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// Created: 03-04-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
//Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
||||||
/*
|
/*
|
||||||
37107287533902102798797998220837590246510135740250
|
37107287533902102798797998220837590246510135740250
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -122,13 +122,14 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem13 extends Problem{
|
public class Problem13 extends Problem{
|
||||||
@@ -291,10 +292,10 @@ public class Problem13 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The sum of all %d numbers is %d\nThe first 10 digits of the sum of the numbers is %s", nums.size(), sum, (sum.toString()).substring(0, 10));
|
return String.format("The sum of all %d numbers is %d%nThe first 10 digits of the sum of the numbers is %s", nums.size(), sum, (sum.toString()).substring(0, 10));
|
||||||
}
|
}
|
||||||
//Returns the list of 50-digit numbers
|
//Returns the list of 50-digit numbers
|
||||||
public ArrayList<BigInteger> getNumbers(){
|
public List<BigInteger> getNumbers(){
|
||||||
solvedCheck("numbers");
|
solvedCheck("numbers");
|
||||||
return nums;
|
return nums;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem14.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem14.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// Created: 03-04-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
/*
|
/*
|
||||||
The following iterative sequence is defined for the set of positive integers:
|
The following iterative sequence is defined for the set of positive integers:
|
||||||
n → n/2 (n is even)
|
n → n/2 (n is even)
|
||||||
@@ -10,7 +10,7 @@ Which starting number, under one million, produces the longest chain?
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -25,7 +25,7 @@ Which starting number, under one million, produces the longest chain?
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem14 extends Problem{
|
public class Problem14 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// Created: 03-04-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//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?
|
//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?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem15 extends Problem{
|
public class Problem15 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// Created: 03-04-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the sum of the digits of the number 2^1000?
|
//What is the sum of the digits of the number 2^1000?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@@ -85,7 +85,7 @@ public class Problem16 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("%d^%d = %s\nThe sum of the elements is %d", NUM_TO_POWER, POWER, num.toString(), sumOfElements);
|
return String.format("%d^%d = %s%nThe sum of the elements is %d", NUM_TO_POWER, POWER, num.toString(), sumOfElements);
|
||||||
}
|
}
|
||||||
//Returns the number that was calculated
|
//Returns the number that was calculated
|
||||||
public BigInteger getNumber(){
|
public BigInteger getNumber(){
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem17.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem17.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// Created: 03-04-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
//If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ProjectEuler.Unsolved;
|
import com.mattrixwv.project_euler.Unsolved;
|
||||||
|
|
||||||
|
|
||||||
public class Problem17 extends Problem{
|
public class Problem17 extends Problem{
|
||||||
@@ -57,8 +57,6 @@ public class Problem17 extends Problem{
|
|||||||
for(int num = START_NUM;num <= STOP_NUM;++num){
|
for(int num = START_NUM;num <= STOP_NUM;++num){
|
||||||
//Pass the number to a function that will create a string for the number
|
//Pass the number to a function that will create a string for the number
|
||||||
String currentNumString = makeWordFromNum(num);
|
String currentNumString = makeWordFromNum(num);
|
||||||
//int count = getNumberChars(currentNumString);
|
|
||||||
//System.out.println(String.format("%4d.Word: %-35s Letters: %d", num, currentNumString, count));
|
|
||||||
//Pass the string to the function that will count the number of letters in it, ignoring whitespace and punctuation and add that number to the running tally
|
//Pass the string to the function that will count the number of letters in it, ignoring whitespace and punctuation and add that number to the running tally
|
||||||
letterCount += getNumberChars(currentNumString);
|
letterCount += getNumberChars(currentNumString);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem18.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem18.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-11-19
|
// Created: 03-11-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the maximum total from top to bottom
|
//Find the maximum total from top to bottom
|
||||||
/*
|
/*
|
||||||
75
|
75
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
//This is done using a breadth first search
|
//This is done using a breadth first search
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -49,13 +49,13 @@ import java.util.Iterator;
|
|||||||
public class Problem18 extends Problem{
|
public class Problem18 extends Problem{
|
||||||
//Structures
|
//Structures
|
||||||
//Used to keep track of where the best location came from
|
//Used to keep track of where the best location came from
|
||||||
protected static class location{
|
protected static class Location{
|
||||||
public int xLocation;
|
public int xLocation;
|
||||||
public int yLocation;
|
public int yLocation;
|
||||||
public int total;
|
public int total;
|
||||||
//Used originally for debugging so I could trace the path backwards
|
//Used originally for debugging so I could trace the path backwards
|
||||||
public boolean fromRight;
|
public boolean fromRight;
|
||||||
location(int x, int y, int t, boolean r){
|
Location(int x, int y, int t, boolean r){
|
||||||
xLocation = x;
|
xLocation = x;
|
||||||
yLocation = y;
|
yLocation = y;
|
||||||
total = t;
|
total = t;
|
||||||
@@ -87,16 +87,16 @@ public class Problem18 extends Problem{
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
//Instance variables
|
//Instance variables
|
||||||
protected ArrayList<location> foundPoints; //For the points that you have already found the shortest distance to
|
protected ArrayList<Location> foundPoints; //For the points that you have already found the shortest distance to
|
||||||
protected ArrayList<location> possiblePoints; //For the locations you are checking this round
|
protected ArrayList<Location> possiblePoints; //For the locations you are checking this round
|
||||||
protected int actualTotal; //The true total of the path from the top to the bottom
|
protected int actualTotal; //The true total of the path from the top to the bottom
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
//Constructor
|
//Constructor
|
||||||
public Problem18(){
|
public Problem18(){
|
||||||
super("Find the maximum total from top to bottom");
|
super("Find the maximum total from top to bottom");
|
||||||
foundPoints = new ArrayList<location>();
|
foundPoints = new ArrayList<>();
|
||||||
possiblePoints = new ArrayList<location>();
|
possiblePoints = new ArrayList<>();
|
||||||
actualTotal = 0;
|
actualTotal = 0;
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
@@ -112,7 +112,7 @@ public class Problem18 extends Problem{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//This function helps by removing the element that is the same as the minimum location
|
//This function helps by removing the element that is the same as the minimum location
|
||||||
protected void removeHelper(ArrayList<location> possiblePoints, final location minLoc){
|
protected void removeHelper(ArrayList<Location> possiblePoints, final Location minLoc){
|
||||||
possiblePoints.removeIf(loc -> ((loc.xLocation == minLoc.xLocation) && (loc.yLocation == minLoc.yLocation)));
|
possiblePoints.removeIf(loc -> ((loc.xLocation == minLoc.xLocation) && (loc.yLocation == minLoc.yLocation)));
|
||||||
}
|
}
|
||||||
//Solve the problem
|
//Solve the problem
|
||||||
@@ -130,17 +130,17 @@ public class Problem18 extends Problem{
|
|||||||
invert(list);
|
invert(list);
|
||||||
|
|
||||||
//Add the first row as a found point because you have to go through the top element
|
//Add the first row as a found point because you have to go through the top element
|
||||||
foundPoints.add(new location(0, 0, list.get(0).get(0), false));
|
foundPoints.add(new Location(0, 0, list.get(0).get(0), false));
|
||||||
//Add the second row as possible points
|
//Add the second row as possible points
|
||||||
possiblePoints.add(new location(0, 1, (list.get(0).get(0) + list.get(1).get(0)), true));
|
possiblePoints.add(new Location(0, 1, (list.get(0).get(0) + list.get(1).get(0)), true));
|
||||||
possiblePoints.add(new location(1, 1, (list.get(0).get(0) + list.get(1).get(1)), false));
|
possiblePoints.add(new Location(1, 1, (list.get(0).get(0) + list.get(1).get(1)), false));
|
||||||
boolean foundBottom = false; //Used when you find a point at the bottom of the list
|
boolean foundBottom = false; //Used when you find a point at the bottom of the list
|
||||||
|
|
||||||
//Loop until you find the bottom of the list
|
//Loop until you find the bottom of the list
|
||||||
while(!foundBottom){
|
while(!foundBottom){
|
||||||
//Check which possible point gives us the lowest number. If more than one has the same number simply keep the first one
|
//Check which possible point gives us the lowest number. If more than one has the same number simply keep the first one
|
||||||
location minLoc = possiblePoints.get(0);
|
Location minLoc = possiblePoints.get(0);
|
||||||
for(location loc : possiblePoints){
|
for(Location loc : possiblePoints){
|
||||||
if(loc.total < minLoc.total){
|
if(loc.total < minLoc.total){
|
||||||
minLoc = loc;
|
minLoc = loc;
|
||||||
}
|
}
|
||||||
@@ -160,12 +160,12 @@ public class Problem18 extends Problem{
|
|||||||
foundBottom = true;
|
foundBottom = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
possiblePoints.add(new location(xLoc, yLoc, minLoc.total + list.get(yLoc).get(xLoc), true));
|
possiblePoints.add(new Location(xLoc, yLoc, minLoc.total + list.get(yLoc).get(xLoc), true));
|
||||||
//Advance the x location to simulate going right
|
//Advance the x location to simulate going right
|
||||||
++xLoc;
|
++xLoc;
|
||||||
//Check if x is out of bounds
|
//Check if x is out of bounds
|
||||||
if(xLoc < list.get(yLoc).size()){
|
if(xLoc < list.get(yLoc).size()){
|
||||||
possiblePoints.add(new location(xLoc, yLoc, minLoc.total + list.get(yLoc).get(xLoc), false));
|
possiblePoints.add(new Location(xLoc, yLoc, minLoc.total + list.get(yLoc).get(xLoc), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,6 +185,7 @@ public class Problem18 extends Problem{
|
|||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
super.reset();
|
super.reset();
|
||||||
foundPoints.clear();
|
foundPoints.clear();
|
||||||
@@ -217,20 +218,20 @@ public class Problem18 extends Problem{
|
|||||||
|
|
||||||
StringBuilder results = new StringBuilder();
|
StringBuilder results = new StringBuilder();
|
||||||
//Save the trail the algorithm took
|
//Save the trail the algorithm took
|
||||||
ArrayList<location> trail = new ArrayList<location>();
|
ArrayList<Location> trail = new ArrayList<Location>();
|
||||||
trail.add(foundPoints.get(foundPoints.size() - 1));
|
trail.add(foundPoints.get(foundPoints.size() - 1));
|
||||||
boolean top = false;
|
boolean top = false;
|
||||||
while(!top){
|
while(!top){
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
int loc = foundPoints.size() - 1;
|
int loc = foundPoints.size() - 1;
|
||||||
location toAdd = null;
|
Location toAdd = null;
|
||||||
while(!found){
|
while(!found){
|
||||||
if(loc < 0){
|
if(loc < 0){
|
||||||
results.append("Error: Location < 0\n");
|
results.append("Error: Location < 0\n");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
Iterator<location> it = foundPoints.iterator();
|
Iterator<Location> it = foundPoints.iterator();
|
||||||
location tempLoc = null;
|
Location tempLoc = null;
|
||||||
for(int cnt = 0;cnt < loc;++cnt){
|
for(int cnt = 0;cnt < loc;++cnt){
|
||||||
tempLoc = it.next();
|
tempLoc = it.next();
|
||||||
}
|
}
|
||||||
@@ -261,7 +262,7 @@ public class Problem18 extends Problem{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(location loc : trail){
|
for(Location loc : trail){
|
||||||
results.append(list.get(loc.yLocation).get(loc.xLocation));
|
results.append(list.get(loc.yLocation).get(loc.xLocation));
|
||||||
if(loc.yLocation < (list.size() - 1)){
|
if(loc.yLocation < (list.size() - 1)){
|
||||||
results.append("->");
|
results.append("->");
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem19.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem19.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-13-19
|
// Created: 03-13-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
//How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
||||||
/*
|
/*
|
||||||
You are given the following information, but you may prefer to do some research for yourself.
|
You are given the following information, but you may prefer to do some research for yourself.
|
||||||
@@ -16,7 +16,7 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -31,14 +31,14 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem19 extends Problem{
|
public class Problem19 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
//An easier way to signal day of the week
|
//An easier way to signal day of the week
|
||||||
private static enum DAYS{SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, NUMBER_OF_DAYS, ERROR};
|
private enum DAYS{SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, NUMBER_OF_DAYS, ERROR};
|
||||||
private static final int START_YEAR = 1901; //The first year we are going to test
|
private static final int START_YEAR = 1901; //The first year we are going to test
|
||||||
private static final int END_YEAR = 2000; //The last year we are going to test
|
private static final int END_YEAR = 2000; //The last year we are going to test
|
||||||
//Instance variables
|
//Instance variables
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//The sum of the even Fibonacci numbers less than 4,000,000
|
//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
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,12 +20,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem2 extends Problem{
|
public class Problem2 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem20.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem20.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-14-19
|
// Created: 03-14-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the sum of the digits of 100!?
|
//What is the sum of the digits of 100!?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@@ -86,7 +86,7 @@ public class Problem20 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("%d! = %s\nThe sum of the digits is: %d", TOP_NUM, num.toString(), sum);
|
return String.format("%d! = %s%nThe sum of the digits is: %d", TOP_NUM, num.toString(), sum);
|
||||||
}
|
}
|
||||||
//Returns the number 100!
|
//Returns the number 100!
|
||||||
public BigInteger getNumber(){
|
public BigInteger getNumber(){
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-18-19
|
// Created: 03-18-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//Evaluate the sum of all the amicable numbers under 10000
|
//Evaluate the sum of all the amicable numbers under 10000
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,11 +20,11 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem22.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem22.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-20-19
|
// Created: 03-20-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the total of all the name scores in this file?
|
//What is the total of all the name scores in this file?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem23.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem23.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-22-19
|
// Created: 03-22-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
|
//Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,11 +20,11 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem24.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem24.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-24-19
|
// Created: 03-24-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.StringAlgorithms;
|
import com.mattrixwv.StringAlgorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem25.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem25.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-25-19
|
// Created: 03-25-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
|
//What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class Problem25 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The first Fibonacci number with %d digits is %s\nIts index is %d", NUM_DIGITS, number.toString(), index);
|
return String.format("The first Fibonacci number with %d digits is %s%nIts index is %d", NUM_DIGITS, number.toString(), index);
|
||||||
}
|
}
|
||||||
//Returns the Fibonacci number asked for
|
//Returns the Fibonacci number asked for
|
||||||
public BigInteger getNumber(){
|
public BigInteger getNumber(){
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem26.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem26.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-28-19
|
// Created: 07-28-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
//Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -97,6 +97,7 @@ public class Problem26 extends Problem{
|
|||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
super.reset();
|
super.reset();
|
||||||
longestCycle = 0;
|
longestCycle = 0;
|
||||||
@@ -107,7 +108,7 @@ public class Problem26 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The longest cycle is %d digits long\nIt started with the number %d", longestCycle, longestNumber);
|
return String.format("The longest cycle is %d digits long%nIt started with the number %d", longestCycle, longestNumber);
|
||||||
}
|
}
|
||||||
//Returns the length of the longest cycle
|
//Returns the length of the longest cycle
|
||||||
public int getLongestCycle(){
|
public int getLongestCycle(){
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem27.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem27.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-15-19
|
// Created: 09-15-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//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.
|
//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.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem27 extends Problem{
|
public class Problem27 extends Problem{
|
||||||
@@ -99,7 +99,7 @@ public class Problem27 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The greatest number of primes found is %d\nIt was found with A = %d, B = %d\nThe product of A and B is %d", topN, topA, topB, topA * topB);
|
return String.format("The greatest number of primes found is %d%nIt was found with A = %d, B = %d%nThe product of A and B is %d", topN, topA, topB, topA * topB);
|
||||||
}
|
}
|
||||||
//Returns the top A that was generated
|
//Returns the top A that was generated
|
||||||
public int getTopA(){
|
public int getTopA(){
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem28.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem28.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-22-19
|
// Created: 09-22-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//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
|
//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
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -28,9 +28,8 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class Problem28 extends Problem{
|
public class Problem28 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
|
||||||
private static ArrayList<ArrayList<Integer>> grid; //Holds the grid that we will be filling and searching
|
|
||||||
//Instance variables
|
//Instance variables
|
||||||
|
private ArrayList<ArrayList<Integer>> grid; //Holds the grid that we will be filling and searching
|
||||||
private int sumOfDiagonals; //Holds the sum of the diagonals of the grid
|
private int sumOfDiagonals; //Holds the sum of the diagonals of the grid
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
@@ -42,11 +41,11 @@ public class Problem28 extends Problem{
|
|||||||
//Operational functions
|
//Operational functions
|
||||||
//Sets up the grid
|
//Sets up the grid
|
||||||
private void setupGrid(){
|
private void setupGrid(){
|
||||||
grid = new ArrayList<ArrayList<Integer>>();
|
grid = new ArrayList<>();
|
||||||
//Fill the grid with 0's
|
//Fill the grid with 0's
|
||||||
for(int cnt = 0;cnt < 1001;++cnt){
|
for(int cnt = 0;cnt < 1001;++cnt){
|
||||||
//Add a blank ArrayList
|
//Add a blank ArrayList
|
||||||
grid.add(new ArrayList<Integer>());
|
grid.add(new ArrayList<>());
|
||||||
for(int cnt2 = 0;cnt2 < 1001;++cnt2){
|
for(int cnt2 = 0;cnt2 < 1001;++cnt2){
|
||||||
grid.get(cnt).add(0);
|
grid.get(cnt).add(0);
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem29.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem29.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-09-19
|
// Created: 10-09-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//The largest prime factor of 600851475143
|
//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
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,14 +20,14 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
import com.mattrixwv.exceptions.InvalidResult;
|
||||||
|
|
||||||
|
|
||||||
public class Problem3 extends Problem{
|
public class Problem3 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem30.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem30.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-27-19
|
// Created: 10-27-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.
|
//Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,12 +20,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem30 extends Problem{
|
public class Problem30 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem31.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem31.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-19-20
|
// Created: 06-19-20
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//How many different ways can £2 be made using any number of coins?
|
//How many different ways can £2 be made using any number of coins?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem31 extends Problem{
|
public class Problem31 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem32.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem32.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-27-20
|
// Created: 07-27-20
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
//Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,12 +20,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import mattrixwv.StringAlgorithms;
|
import com.mattrixwv.StringAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem32 extends Problem{
|
public class Problem32 extends Problem{
|
||||||
@@ -81,7 +81,7 @@ public class Problem32 extends Problem{
|
|||||||
//Constructor
|
//Constructor
|
||||||
public Problem32(){
|
public Problem32(){
|
||||||
super("Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.");
|
super("Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.");
|
||||||
listOfProducts = new ArrayList<ProductSet>();
|
listOfProducts = new ArrayList<>();
|
||||||
sumOfPandigitals = 0;
|
sumOfPandigitals = 0;
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
@@ -157,7 +157,7 @@ public class Problem32 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("There are %d unique 1-9 pandigitals\nThe sum of the products of these pandigitals is %d", listOfProducts.size(), sumOfPandigitals);
|
return String.format("There are %d unique 1-9 pandigitals%nThe sum of the products of these pandigitals is %d", listOfProducts.size(), sumOfPandigitals);
|
||||||
}
|
}
|
||||||
//Returns the sum of the pandigitals
|
//Returns the sum of the pandigitals
|
||||||
public long getSumOfPandigitals(){
|
public long getSumOfPandigitals(){
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem33.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem33.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 02-05-21
|
// Created: 02-05-21
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
/*
|
/*
|
||||||
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s
|
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s
|
||||||
We shall consider fractions like, 30/50 = 3/5, to be trivial examples
|
We shall consider fractions like, 30/50 = 3/5, to be trivial examples
|
||||||
@@ -10,7 +10,7 @@ If the product of these four fractions is given in its lowest common terms, find
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -25,13 +25,14 @@ If the product of these four fractions is given in its lowest common terms, find
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem33 extends Problem{
|
public class Problem33 extends Problem{
|
||||||
@@ -51,8 +52,8 @@ public class Problem33 extends Problem{
|
|||||||
public Problem33(){
|
public Problem33(){
|
||||||
super("If the product of these four fractions is given in its lowest common terms, find the value of the denominator");
|
super("If the product of these four fractions is given in its lowest common terms, find the value of the denominator");
|
||||||
prodDenominator = 1;
|
prodDenominator = 1;
|
||||||
numerators = new ArrayList<Integer>();
|
numerators = new ArrayList<>();
|
||||||
denominators = new ArrayList<Integer>();
|
denominators = new ArrayList<>();
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
//Solve the problem
|
//Solve the problem
|
||||||
@@ -135,12 +136,12 @@ public class Problem33 extends Problem{
|
|||||||
return String.format("The denominator of the product is %d", prodDenominator);
|
return String.format("The denominator of the product is %d", prodDenominator);
|
||||||
}
|
}
|
||||||
//Returns the list of numerators
|
//Returns the list of numerators
|
||||||
public ArrayList<Integer> getNumerators(){
|
public List<Integer> getNumerators(){
|
||||||
solvedCheck("list of numerators");
|
solvedCheck("list of numerators");
|
||||||
return numerators;
|
return numerators;
|
||||||
}
|
}
|
||||||
//Returns the list of denominators
|
//Returns the list of denominators
|
||||||
public ArrayList<Integer> getDenominators(){
|
public List<Integer> getDenominators(){
|
||||||
solvedCheck("list of denominators");
|
solvedCheck("list of denominators");
|
||||||
return denominators;
|
return denominators;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem34.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem34.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 02-05-21
|
// Created: 02-05-21
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the sum of all numbers which are equal to the sum of the factorial of their digits
|
//Find the sum of all numbers which are equal to the sum of the factorial of their digits
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,12 +20,13 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem34 extends Problem{
|
public class Problem34 extends Problem{
|
||||||
@@ -41,7 +42,7 @@ public class Problem34 extends Problem{
|
|||||||
public Problem34(){
|
public Problem34(){
|
||||||
super("Find the sum of all numbers which are equal to the sum of the factorial of their digits");
|
super("Find the sum of all numbers which are equal to the sum of the factorial of their digits");
|
||||||
sum = 0;
|
sum = 0;
|
||||||
factorials = new ArrayList<Integer>();
|
factorials = new ArrayList<>();
|
||||||
for(int cnt = 0;cnt <= 9;++cnt){
|
for(int cnt = 0;cnt <= 9;++cnt){
|
||||||
factorials.add(0);
|
factorials.add(0);
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ public class Problem34 extends Problem{
|
|||||||
int currentSum = 0;
|
int currentSum = 0;
|
||||||
for(int charCnt = 0;charCnt < numString.length();++charCnt){
|
for(int charCnt = 0;charCnt < numString.length();++charCnt){
|
||||||
Character digit = numString.charAt(charCnt);
|
Character digit = numString.charAt(charCnt);
|
||||||
int tempNum = Integer.valueOf(digit.toString());
|
int tempNum = Integer.parseInt(digit.toString());
|
||||||
currentSum += factorials.get(tempNum);
|
currentSum += factorials.get(tempNum);
|
||||||
}
|
}
|
||||||
//If the number is equal to the sum add the sum to the running sum
|
//If the number is equal to the sum add the sum to the running sum
|
||||||
@@ -85,11 +86,12 @@ public class Problem34 extends Problem{
|
|||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
//Reset the proble so it can be run again
|
//Reset the problem so it can be run again
|
||||||
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
super.reset();
|
super.reset();
|
||||||
sum = 0;
|
sum = 0;
|
||||||
factorials = new ArrayList<Integer>();
|
factorials = new ArrayList<>();
|
||||||
for(int cnt = 0;cnt <= 9;++cnt){
|
for(int cnt = 0;cnt <= 9;++cnt){
|
||||||
factorials.add(0);
|
factorials.add(0);
|
||||||
}
|
}
|
||||||
@@ -102,7 +104,7 @@ public class Problem34 extends Problem{
|
|||||||
return String.format("The sum of all numbers that are the sum of their digit's factorials is %d", sum);
|
return String.format("The sum of all numbers that are the sum of their digit's factorials is %d", sum);
|
||||||
}
|
}
|
||||||
//Returns the list of factorials from 0-9
|
//Returns the list of factorials from 0-9
|
||||||
public ArrayList<Integer> getFactorials(){
|
public List<Integer> getFactorials(){
|
||||||
solvedCheck("list of factorials");
|
solvedCheck("list of factorials");
|
||||||
return factorials;
|
return factorials;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem35.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem35.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-05-21
|
// Created: 06-05-21
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//How many circular primes are there below one million?
|
//How many circular primes are there below one million?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,13 +20,13 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem35 extends Problem{
|
public class Problem35 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem36.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem36.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-29-21
|
// Created: 06-29-21
|
||||||
//Modified: 06-29-21
|
//Modified: 08-20-22
|
||||||
//Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
|
//Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,14 +20,15 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
import mattrixwv.StringAlgorithms;
|
import com.mattrixwv.StringAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem36 extends Problem{
|
public class Problem36 extends Problem{
|
||||||
@@ -42,7 +43,7 @@ public class Problem36 extends Problem{
|
|||||||
//Constructor
|
//Constructor
|
||||||
public Problem36(){
|
public Problem36(){
|
||||||
super("Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.");
|
super("Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.");
|
||||||
palindromes = new ArrayList<Integer>();
|
palindromes = new ArrayList<>();
|
||||||
sum = 0;
|
sum = 0;
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
@@ -80,6 +81,7 @@ public class Problem36 extends Problem{
|
|||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
super.reset();
|
super.reset();
|
||||||
palindromes.clear();
|
palindromes.clear();
|
||||||
@@ -92,7 +94,7 @@ public class Problem36 extends Problem{
|
|||||||
return String.format("The sum of all base 10 and base 2 palindromic numbers < %d is %d", MAX_NUM, sum);
|
return String.format("The sum of all base 10 and base 2 palindromic numbers < %d is %d", MAX_NUM, sum);
|
||||||
}
|
}
|
||||||
//Return the List of palindromes < MAX_NUM
|
//Return the List of palindromes < MAX_NUM
|
||||||
public ArrayList<Integer> getPalindromes(){
|
public List<Integer> getPalindromes(){
|
||||||
solvedCheck("list of palindromes");
|
solvedCheck("list of palindromes");
|
||||||
return palindromes;
|
return palindromes;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem37.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem37.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-01-21
|
// Created: 07-01-21
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted).
|
//Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted).
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,13 +20,16 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.mattrixwv.ArrayAlgorithms;
|
||||||
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
import com.mattrixwv.generators.SieveOfEratosthenes;
|
||||||
|
|
||||||
import mattrixwv.ArrayAlgorithms;
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
|
||||||
import mattrixwv.SieveOfEratosthenes;
|
|
||||||
|
|
||||||
public class Problem37 extends Problem{
|
public class Problem37 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
@@ -40,7 +43,7 @@ public class Problem37 extends Problem{
|
|||||||
//Constructor
|
//Constructor
|
||||||
public Problem37(){
|
public Problem37(){
|
||||||
super("Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted).");
|
super("Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted).");
|
||||||
truncPrimes = new ArrayList<Long>();
|
truncPrimes = new ArrayList<>();
|
||||||
sum = 0;
|
sum = 0;
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
@@ -89,7 +92,7 @@ public class Problem37 extends Problem{
|
|||||||
//Create a substring of the prime, removing the needed digits from the left
|
//Create a substring of the prime, removing the needed digits from the left
|
||||||
String primeSubstring = primeString.substring(truncLoc);
|
String primeSubstring = primeString.substring(truncLoc);
|
||||||
//Convert the string to an int and see if the number is still prime
|
//Convert the string to an int and see if the number is still prime
|
||||||
long newPrime = Long.valueOf(primeSubstring);
|
long newPrime = Long.parseLong(primeSubstring);
|
||||||
if(!NumberAlgorithms.isPrime(newPrime)){
|
if(!NumberAlgorithms.isPrime(newPrime)){
|
||||||
isTruncPrime = false;
|
isTruncPrime = false;
|
||||||
break;
|
break;
|
||||||
@@ -102,7 +105,7 @@ public class Problem37 extends Problem{
|
|||||||
//Create a substring of the prime, removing the needed digits from the right
|
//Create a substring of the prime, removing the needed digits from the right
|
||||||
String primeSubstring = primeString.substring(0, primeString.length() - truncLoc);
|
String primeSubstring = primeString.substring(0, primeString.length() - truncLoc);
|
||||||
//Convert the string to an int and see if the number is still prime
|
//Convert the string to an int and see if the number is still prime
|
||||||
long newPrime = Long.valueOf(primeSubstring);
|
long newPrime = Long.parseLong(primeSubstring);
|
||||||
if(!NumberAlgorithms.isPrime(newPrime)){
|
if(!NumberAlgorithms.isPrime(newPrime)){
|
||||||
isTruncPrime = false;
|
isTruncPrime = false;
|
||||||
break;
|
break;
|
||||||
@@ -125,6 +128,7 @@ public class Problem37 extends Problem{
|
|||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
super.reset();
|
super.reset();
|
||||||
truncPrimes.clear();
|
truncPrimes.clear();
|
||||||
@@ -138,7 +142,7 @@ public class Problem37 extends Problem{
|
|||||||
return String.format("The sum of all left and right truncatable primes is %d", sum);
|
return String.format("The sum of all left and right truncatable primes is %d", sum);
|
||||||
}
|
}
|
||||||
//Returns the list of primes that can be truncated
|
//Returns the list of primes that can be truncated
|
||||||
public ArrayList<Long> getTruncatablePrimes(){
|
public List<Long> getTruncatablePrimes(){
|
||||||
solvedCheck("list of truncatable primes");
|
solvedCheck("list of truncatable primes");
|
||||||
return truncPrimes;
|
return truncPrimes;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem37.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem37.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-11-21
|
// Created: 10-11-21
|
||||||
//Modified: 10-11-21
|
//Modified: 08-20-22
|
||||||
//What is the largest 1-9 pandigital number that can be formed as the concatenated product of an integer with 1, 2, ... n where n > 1
|
//What is the largest 1-9 pandigital number that can be formed as the concatenated product of an integer with 1, 2, ... n where n > 1
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.StringAlgorithms;
|
import com.mattrixwv.StringAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem38 extends Problem{
|
public class Problem38 extends Problem{
|
||||||
@@ -45,15 +45,16 @@ public class Problem38 extends Problem{
|
|||||||
//Take the number and add its multiples to a string to return
|
//Take the number and add its multiples to a string to return
|
||||||
private String executeFormula(int num){
|
private String executeFormula(int num){
|
||||||
//Turn the current number into a string
|
//Turn the current number into a string
|
||||||
String numStr = Integer.toString(num);
|
StringBuilder numStr = new StringBuilder();
|
||||||
|
numStr.append(Integer.toString(num));
|
||||||
int cnt = 2;
|
int cnt = 2;
|
||||||
//Multiply the number and append the product to the string until you have one long enough
|
//Multiply the number and append the product to the string until you have one long enough
|
||||||
do{
|
do{
|
||||||
numStr += Integer.toString(num * cnt);
|
numStr.append(Integer.toString(num * cnt));
|
||||||
++cnt;
|
++cnt;
|
||||||
}while(numStr.length() < 9);
|
}while(numStr.length() < 9);
|
||||||
|
|
||||||
return numStr;
|
return numStr.toString();
|
||||||
}
|
}
|
||||||
//Solve the problem
|
//Solve the problem
|
||||||
public void solve(){
|
public void solve(){
|
||||||
@@ -86,6 +87,7 @@ public class Problem38 extends Problem{
|
|||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
//Reset the prblem so it can be run again
|
//Reset the prblem so it can be run again
|
||||||
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
super.reset();
|
super.reset();
|
||||||
largestNum = 0;
|
largestNum = 0;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the largest palindrome made from the product of two 3-digit numbers
|
//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
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 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
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem5 extends Problem{
|
public class Problem5 extends Problem{
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
//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
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem6 extends Problem{
|
public class Problem6 extends Problem{
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-01-19
|
// Created: 03-01-19
|
||||||
//Modified: 07-30-22
|
//Modified: 08-20-22
|
||||||
//What is the 10001th prime number?
|
//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
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
@@ -20,13 +20,13 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mattrixwv.NumberAlgorithms;
|
import com.mattrixwv.NumberAlgorithms;
|
||||||
|
|
||||||
|
|
||||||
public class Problem7 extends Problem{
|
public class Problem7 extends Problem{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-28-19
|
// Created: 03-28-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
//Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
||||||
/*
|
/*
|
||||||
73167176531330624919225119674426574742355349194934
|
73167176531330624919225119674426574742355349194934
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
public class Problem8 extends Problem{
|
public class Problem8 extends Problem{
|
||||||
@@ -104,7 +104,7 @@ public class Problem8 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The greatest product is %d\nThe numbers are %s", maxProduct, maxNums);
|
return String.format("The greatest product is %d%nThe numbers are %s", maxProduct, maxNums);
|
||||||
}
|
}
|
||||||
//Returns the string of numbers that produces the largest product
|
//Returns the string of numbers that produces the largest product
|
||||||
public String getLargestNums(){
|
public String getLargestNums(){
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-02-19
|
// Created: 03-02-19
|
||||||
//Modified: 07-03-21
|
//Modified: 08-20-22
|
||||||
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
|
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package com.mattrixwv.project_euler.problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ProjectEuler.Unsolved;
|
import com.mattrixwv.project_euler.Unsolved;
|
||||||
|
|
||||||
|
|
||||||
public class Problem9 extends Problem{
|
public class Problem9 extends Problem{
|
||||||
@@ -104,7 +104,7 @@ public class Problem9 extends Problem{
|
|||||||
@Override
|
@Override
|
||||||
public String getResult(){
|
public String getResult(){
|
||||||
solvedCheck("result");
|
solvedCheck("result");
|
||||||
return String.format("The Pythagorean triplet is %d + %d + %d\nThe numbers' product is %d", a, b, Math.round(c), a * b * Math.round(c));
|
return String.format("The Pythagorean triplet is %d + %d + %d%nThe numbers' product is %d", a, b, Math.round(c), a * b * Math.round(c));
|
||||||
}
|
}
|
||||||
//Returns the length of the first side
|
//Returns the length of the first side
|
||||||
public int getSideA(){
|
public int getSideA(){
|
||||||
Reference in New Issue
Block a user