mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Update sonarqube findings
This commit is contained in:
@@ -37,7 +37,7 @@ public class Problem11 extends Problem{
|
|||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
//This is the grid of numbers that we will be working with
|
//This is the grid of numbers that we will be working with
|
||||||
protected static String FILE_NAME = "files/Problem11Grid.txt";
|
protected static String fileName = "files/Problem11Grid.txt";
|
||||||
protected static ArrayList<List<Integer>> grid;
|
protected static ArrayList<List<Integer>> grid;
|
||||||
//Instance variables
|
//Instance variables
|
||||||
protected List<Integer> greatestProduct; //Holds the largest product we have found so far
|
protected List<Integer> greatestProduct; //Holds the largest product we have found so far
|
||||||
@@ -50,11 +50,11 @@ public class Problem11 extends Problem{
|
|||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
//Read numbers from file into grid
|
//Read numbers from file into grid
|
||||||
private void readFile(){
|
private static void readFile(){
|
||||||
if(grid != null){
|
if(grid != null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(FILE_NAME);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
try{
|
try{
|
||||||
List<String> lines = Files.readAllLines(file.toPath());
|
List<String> lines = Files.readAllLines(file.toPath());
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import com.mattrixwv.ArrayAlgorithms;
|
|||||||
public class Problem13 extends Problem{
|
public class Problem13 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
protected static String FILE_NAME = "files/Problem13Numbers.txt";
|
protected static String fileName = "files/Problem13Numbers.txt";
|
||||||
protected static ArrayList<BigInteger> nums; //Holds the numbers that are being summed
|
protected static ArrayList<BigInteger> nums; //Holds the numbers that are being summed
|
||||||
//Instance variables
|
//Instance variables
|
||||||
protected BigInteger sum; //The sum of all the numbers
|
protected BigInteger sum; //The sum of all the numbers
|
||||||
@@ -50,11 +50,11 @@ public class Problem13 extends Problem{
|
|||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
//Read number from file into nums
|
//Read number from file into nums
|
||||||
private void readFile(){
|
private static void readFile(){
|
||||||
if(nums != null){
|
if(nums != null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(FILE_NAME);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
try{
|
try{
|
||||||
List<String> lines = Files.readAllLines(file.toPath());
|
List<String> lines = Files.readAllLines(file.toPath());
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class Problem18 extends Problem{
|
|||||||
|
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
protected String FILE_NAME = "files/Problem18Pyramid.txt";
|
protected String fileName = "files/Problem18Pyramid.txt";
|
||||||
protected static ArrayList<ArrayList<Integer>> list; //The list to hold the numbers in
|
protected static ArrayList<ArrayList<Integer>> list; //The list to hold the numbers in
|
||||||
//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
|
||||||
@@ -83,7 +83,7 @@ public class Problem18 extends Problem{
|
|||||||
if(list != null){
|
if(list != null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(FILE_NAME);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
try{
|
try{
|
||||||
List<String> lines = Files.readAllLines(file.toPath());
|
List<String> lines = Files.readAllLines(file.toPath());
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import java.util.List;
|
|||||||
public class Problem22 extends Problem{
|
public class Problem22 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
protected static String FILE_NAME = "files/Problem22Names.txt";
|
protected static String fileName = "files/Problem22Names.txt";
|
||||||
//Holds the names that will be scored
|
//Holds the names that will be scored
|
||||||
protected static ArrayList<String> names = new ArrayList<>();
|
protected static ArrayList<String> names = new ArrayList<>();
|
||||||
//Instance variables
|
//Instance variables
|
||||||
@@ -59,7 +59,7 @@ public class Problem22 extends Problem{
|
|||||||
if(!names.isEmpty()){
|
if(!names.isEmpty()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(FILE_NAME);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
try{
|
try{
|
||||||
List<String> lines = Files.readAllLines(file.toPath());
|
List<String> lines = Files.readAllLines(file.toPath());
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import java.util.List;
|
|||||||
public class Problem42 extends Problem{
|
public class Problem42 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
protected static String FILE_NAME = "files/Problem42Words.txt";
|
protected static String fileName = "files/Problem42Words.txt";
|
||||||
protected static ArrayList<String> fileWords = new ArrayList<>();
|
protected static ArrayList<String> fileWords = new ArrayList<>();
|
||||||
//Instance variables
|
//Instance variables
|
||||||
protected ArrayList<String> triangleWords;
|
protected ArrayList<String> triangleWords;
|
||||||
@@ -51,7 +51,7 @@ public class Problem42 extends Problem{
|
|||||||
if(!fileWords.isEmpty()){
|
if(!fileWords.isEmpty()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(FILE_NAME);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
try{
|
try{
|
||||||
List<String> lines = Files.readAllLines(file.toPath());
|
List<String> lines = Files.readAllLines(file.toPath());
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class Problem67 extends Problem18{
|
|||||||
//Setup the list of numbers to check
|
//Setup the list of numbers to check
|
||||||
public Problem67(){
|
public Problem67(){
|
||||||
super();
|
super();
|
||||||
FILE_NAME = "files/Problem67Pyramid.txt";
|
fileName = "files/Problem67Pyramid.txt";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class Problem8 extends Problem{
|
|||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
//The 1000 digit number to check
|
//The 1000 digit number to check
|
||||||
protected static String FILE_NAME = "files/Problem8Number.txt";
|
protected static String fileName = "files/Problem8Number.txt";
|
||||||
protected static String number;
|
protected static String number;
|
||||||
//Instance variables
|
//Instance variables
|
||||||
protected String maxNums; //Holds the string of the largest product
|
protected String maxNums; //Holds the string of the largest product
|
||||||
@@ -47,11 +47,11 @@ public class Problem8 extends Problem{
|
|||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
//Read number from file into number
|
//Read number from file into number
|
||||||
private void readFile(){
|
private static void readFile(){
|
||||||
if(number != null){
|
if(number != null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(FILE_NAME);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
try{
|
try{
|
||||||
List<String> lines = Files.readAllLines(file.toPath());
|
List<String> lines = Files.readAllLines(file.toPath());
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import com.mattrixwv.project_euler.exceptions.Unsolved;
|
|||||||
public class Problem9 extends Problem{
|
public class Problem9 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
protected int GOAL_SUM = 1000; //The number that we want the sum of a, b, and c to equal
|
protected int goalSum = 1000; //The number that we want the sum of a, b, and c to equal
|
||||||
//Instance variables
|
//Instance variables
|
||||||
protected int a; //The size of the first side
|
protected int a; //The size of the first side
|
||||||
protected int b; //The size of the second side
|
protected int b; //The size of the second side
|
||||||
@@ -59,18 +59,18 @@ public class Problem9 extends Problem{
|
|||||||
|
|
||||||
|
|
||||||
//Loop through all possible a's
|
//Loop through all possible a's
|
||||||
while((a < GOAL_SUM) && !found){
|
while((a < goalSum) && !found){
|
||||||
b = a + 1; //b must be larger than a
|
b = a + 1; //b must be larger than a
|
||||||
c = Math.sqrt((a * a) + (double)(b * b)); //Compute the hyp
|
c = Math.sqrt((a * a) + (double)(b * b)); //Compute the hyp
|
||||||
|
|
||||||
//Loop through all possible b's for this a
|
//Loop through all possible b's for this a
|
||||||
while((a + b + c) < GOAL_SUM){
|
while((a + b + c) < goalSum){
|
||||||
++b;
|
++b;
|
||||||
c = Math.sqrt((a * a) + (double)(b * b));
|
c = Math.sqrt((a * a) + (double)(b * b));
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the sum == 1000 you found the number, otherwise go to the next possible a
|
//If the sum == 1000 you found the number, otherwise go to the next possible a
|
||||||
if((a + b + c) == GOAL_SUM){
|
if((a + b + c) == goalSum){
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class TestProblem11 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem11.grid = null;
|
Problem11.grid = null;
|
||||||
RandomAccessFile file = new RandomAccessFile(Problem11.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(Problem11.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -81,7 +81,7 @@ public class TestProblem11 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem11.grid = null;
|
Problem11.grid = null;
|
||||||
Problem11.FILE_NAME = "/a";
|
Problem11.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class TestProblem13 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem13.nums = null;
|
Problem13.nums = null;
|
||||||
RandomAccessFile file = new RandomAccessFile(Problem13.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(Problem13.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -79,7 +79,7 @@ public class TestProblem13 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem13.nums = null;
|
Problem13.nums = null;
|
||||||
Problem13.FILE_NAME = "/a";
|
Problem13.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class TestProblem18 extends TestProblemBase{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verifyReset(){
|
public void verifyReset(){
|
||||||
assertEquals("files/Problem18Pyramid.txt", problem.FILE_NAME);
|
assertEquals("files/Problem18Pyramid.txt", problem.fileName);
|
||||||
assertEquals(new ArrayList<>(), problem.foundPoints);
|
assertEquals(new ArrayList<>(), problem.foundPoints);
|
||||||
assertEquals(new ArrayList<>(), problem.possiblePoints);
|
assertEquals(new ArrayList<>(), problem.possiblePoints);
|
||||||
assertEquals(0, problem.actualTotal);
|
assertEquals(0, problem.actualTotal);
|
||||||
@@ -74,7 +74,7 @@ public class TestProblem18 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem18.list = null;
|
Problem18.list = null;
|
||||||
RandomAccessFile file = new RandomAccessFile(problem.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(problem.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -89,7 +89,7 @@ public class TestProblem18 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem18.list = null;
|
Problem18.list = null;
|
||||||
problem.FILE_NAME = "/a";
|
problem.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class TestProblem22 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem22.names = new ArrayList<>();
|
Problem22.names = new ArrayList<>();
|
||||||
RandomAccessFile file = new RandomAccessFile(Problem22.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(Problem22.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -84,7 +84,7 @@ public class TestProblem22 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem22.names = new ArrayList<>();
|
Problem22.names = new ArrayList<>();
|
||||||
Problem22.FILE_NAME = "/a";
|
Problem22.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class TestProblem42 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem42.fileWords = new ArrayList<>();
|
Problem42.fileWords = new ArrayList<>();
|
||||||
RandomAccessFile file = new RandomAccessFile(Problem42.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(Problem42.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -78,7 +78,7 @@ public class TestProblem42 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem42.fileWords = new ArrayList<>();
|
Problem42.fileWords = new ArrayList<>();
|
||||||
Problem42.FILE_NAME = "/a";
|
Problem42.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class TestProblem67 extends TestProblemBase{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verifyReset(){
|
public void verifyReset(){
|
||||||
assertEquals("files/Problem67Pyramid.txt", problem.FILE_NAME);
|
assertEquals("files/Problem67Pyramid.txt", problem.fileName);
|
||||||
assertEquals(new ArrayList<>(), problem.foundPoints);
|
assertEquals(new ArrayList<>(), problem.foundPoints);
|
||||||
assertEquals(new ArrayList<>(), problem.possiblePoints);
|
assertEquals(new ArrayList<>(), problem.possiblePoints);
|
||||||
assertEquals(0, problem.actualTotal);
|
assertEquals(0, problem.actualTotal);
|
||||||
@@ -69,7 +69,7 @@ public class TestProblem67 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem67.list = null;
|
Problem67.list = null;
|
||||||
RandomAccessFile file = new RandomAccessFile(problem.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(problem.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -84,7 +84,7 @@ public class TestProblem67 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem67.list = null;
|
Problem67.list = null;
|
||||||
problem.FILE_NAME = "/a";
|
problem.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class TestProblem8 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem8.number = null;
|
Problem8.number = null;
|
||||||
RandomAccessFile file = new RandomAccessFile(Problem8.FILE_NAME, "rw");
|
RandomAccessFile file = new RandomAccessFile(Problem8.fileName, "rw");
|
||||||
file.getChannel().lock();
|
file.getChannel().lock();
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
@@ -81,7 +81,7 @@ public class TestProblem8 extends TestProblemBase{
|
|||||||
problem.reset();
|
problem.reset();
|
||||||
|
|
||||||
Problem8.number = null;
|
Problem8.number = null;
|
||||||
Problem8.FILE_NAME = "/a";
|
Problem8.fileName = "/a";
|
||||||
|
|
||||||
assertThrows(InvalidParameterException.class, () -> {
|
assertThrows(InvalidParameterException.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class TestProblem9 extends TestProblemBase{
|
|||||||
@Test
|
@Test
|
||||||
public void testSolve_notFound(){
|
public void testSolve_notFound(){
|
||||||
problem.reset();
|
problem.reset();
|
||||||
problem.GOAL_SUM = 1;
|
problem.goalSum = 1;
|
||||||
|
|
||||||
assertThrows(Unsolved.class, () -> {
|
assertThrows(Unsolved.class, () -> {
|
||||||
problem.solve();
|
problem.solve();
|
||||||
|
|||||||
Reference in New Issue
Block a user