mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Updated problem's flow to match the other languages
This commit is contained in:
@@ -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-17-20
|
//Modified: 08-23-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
@@ -67,7 +67,7 @@ public class Problem1 extends Problem{
|
|||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
//Save the results
|
//Save the results
|
||||||
result = "The sum of all numbers < " + (TOP_NUM + 1) + " is " + fullSum;
|
result = String.format("The sum of all numbers < %d is %d", (TOP_NUM + 1), fullSum);
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
@@ -57,11 +57,11 @@ public class Problem10 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("The sum of all the primes < %d is %d\n", GOAL_NUMBER + 1, sum);
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("The sum of all the primes < %d is %d\n", GOAL_NUMBER + 1, sum);
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
@@ -194,11 +194,11 @@ public class Problem11 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the resutls
|
|
||||||
result = String.format("The greatest product of 4 numbers in a line is %d\nThe numbers are %s", Algorithms.getProd(greatestProduct), greatestProduct.toString());
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the resutls
|
||||||
|
result = String.format("The greatest product of 4 numbers in a line is %d\nThe numbers are %s", Algorithms.getProd(greatestProduct), greatestProduct.toString());
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
@@ -77,11 +77,11 @@ public class Problem12 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("The triangular number %d is the sum of all numbers >= %d and has %d divisors\n", sum, counter - 1, divisors.size());
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("The triangular number %d is the sum of all numbers >= %d and has %d divisors\n", sum, counter - 1, divisors.size());
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
@@ -274,11 +274,11 @@ public class Problem13 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("The sum of all %d numbers is %d\nThe first 10 digits of the sum of the numbers is %s\n", nums.size(), sum, (sum.toString()).substring(0, 10));
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("The sum of all %d numbers is %d\nThe first 10 digits of the sum of the numbers is %s\n", nums.size(), sum, (sum.toString()).substring(0, 10));
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -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-18-20
|
//Modified: 08-26-20
|
||||||
/*
|
/*
|
||||||
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)
|
||||||
@@ -70,11 +70,11 @@ public class Problem14 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("The number %d produced a chain of %d steps\n", maxNum, maxLength);
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("The number %d produced a chain of %d steps\n", maxNum, maxLength);
|
||||||
}
|
}
|
||||||
//This function follows the rules of the sequence and returns its length
|
//This function follows the rules of the sequence and returns its length
|
||||||
private long checkSeries(long num){
|
private long checkSeries(long num){
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
@@ -22,8 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
package mattrixwv.ProjectEuler.Problems;
|
package mattrixwv.ProjectEuler.Problems;
|
||||||
|
|
||||||
|
|
||||||
import mattrixwv.ProjectEuler.Unsolved;
|
import mattrixwv.ProjectEuler.Unsolved;
|
||||||
|
|
||||||
|
|
||||||
public class Problem15 extends Problem{
|
public class Problem15 extends Problem{
|
||||||
//Variables
|
//Variables
|
||||||
//Static vaiables
|
//Static vaiables
|
||||||
@@ -56,11 +58,11 @@ public class Problem15 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("The number of routes is " + numOfRoutes);
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("The number of routes is " + numOfRoutes);
|
||||||
}
|
}
|
||||||
//This function acts as a handler for moving the position on the grid and counting the distance
|
//This function acts as a handler for moving the position on the grid and counting the distance
|
||||||
//It moves right first, then down
|
//It moves right first, then down
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
@@ -67,11 +67,11 @@ public class Problem16 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("%d^%d = %s\nThe sum of the elements is %d\n", NUM_TO_POWER, POWER, num.toString(), sumOfElements);
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("%d^%d = %s\nThe sum of the elements is %d\n", NUM_TO_POWER, POWER, num.toString(), sumOfElements);
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
@@ -62,11 +62,11 @@ public class Problem17 extends Problem{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
//Save the results
|
|
||||||
result = String.format("The sum of all the letters in all the numbers %d-%d is %d\n", START_NUM, STOP_NUM, letterCount);
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
//Save the results
|
||||||
|
result = String.format("The sum of all the letters in all the numbers %d-%d is %d\n", START_NUM, STOP_NUM, letterCount);
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
@@ -75,103 +75,71 @@ public class Problem17 extends Problem{
|
|||||||
}
|
}
|
||||||
//This function makes a word out of the number passed into it
|
//This function makes a word out of the number passed into it
|
||||||
private String getStringFromNum(int number){
|
private String getStringFromNum(int number){
|
||||||
String numberString = new String();
|
StringBuilder numberString = new StringBuilder();
|
||||||
//Starting with the largest digit create a string based on the number passed in
|
//Starting with the largest digit create a string based on the number passed in
|
||||||
//Check for negative
|
//Check for negative
|
||||||
if(number < 0){
|
if(number < 0){
|
||||||
numberString = numberString.concat("negative ");
|
numberString = numberString.append("negative ");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if the number is zero
|
//Check if the number is zero
|
||||||
if(number == 0){
|
if(number == 0){
|
||||||
numberString = numberString.concat("zero");
|
numberString = numberString.append("zero");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Start with the thousands place
|
//Start with the thousands place
|
||||||
if((number / 1000D) >= 1D){
|
if((number / 1000D) >= 1D){
|
||||||
numberString = numberString.concat(getStringFromNum((int)Math.floor(number / 1000D)));
|
numberString = numberString.append(getStringFromNum((int)Math.floor(number / 1000D)));
|
||||||
numberString = numberString.concat(" thousand");
|
numberString = numberString.append(" thousand");
|
||||||
number -= ((int)Math.floor(number / 1000D)) * 1000;
|
number -= ((int)Math.floor(number / 1000D)) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check the hundreds place
|
//Check the hundreds place
|
||||||
if((number / 100D) >= 1D){
|
if((number / 100D) >= 1D){
|
||||||
numberString = numberString.concat(getStringFromNum((int)Math.floor(number / 100D)));
|
numberString = numberString.append(getStringFromNum((int)Math.floor(number / 100D)));
|
||||||
numberString = numberString.concat(" hundred");
|
numberString = numberString.append(" hundred");
|
||||||
number -= ((int)Math.floor(number / 100D)) * 100;
|
number -= ((int)Math.floor(number / 100D)) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Insert an and if there is need
|
//Insert an and if there is need
|
||||||
if((!numberString.isBlank() && (number > 0))){
|
if((!numberString.toString().isBlank() && (number > 0))){
|
||||||
numberString = numberString.concat(" and ");
|
numberString = numberString.append(" and ");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for tens place
|
//Check for tens place
|
||||||
if((number / 10D) >= 2D){
|
if((number / 10D) >= 2D){
|
||||||
//For the tens you need to do something special
|
//For the tens you need to do something special
|
||||||
int tensPlace = (int)Math.floor(number / 10D);
|
int tensPlace = (int)Math.floor(number / 10D);
|
||||||
if(tensPlace == 9){
|
switch(tensPlace){
|
||||||
numberString = numberString.concat("ninety");
|
case 9: numberString.append("ninety"); break;
|
||||||
}
|
case 8: numberString.append("eighty"); break;
|
||||||
else if(tensPlace == 8){
|
case 7: numberString.append("seventy"); break;
|
||||||
numberString = numberString.concat("eighty");
|
case 6: numberString.append("sixty"); break;
|
||||||
}
|
case 5: numberString.append("fifty"); break;
|
||||||
else if(tensPlace == 7){
|
case 4: numberString.append("forty"); break;
|
||||||
numberString = numberString.concat("seventy");
|
case 3: numberString.append("thirty"); break;
|
||||||
}
|
case 2: numberString.append("twenty"); break;
|
||||||
else if(tensPlace == 6){
|
|
||||||
numberString = numberString.concat("sixty");
|
|
||||||
}
|
|
||||||
else if(tensPlace == 5){
|
|
||||||
numberString = numberString.concat("fifty");
|
|
||||||
}
|
|
||||||
else if(tensPlace == 4){
|
|
||||||
numberString = numberString.concat("forty");
|
|
||||||
}
|
|
||||||
else if(tensPlace == 3){
|
|
||||||
numberString = numberString.concat("thirty");
|
|
||||||
}
|
|
||||||
else if(tensPlace == 2){
|
|
||||||
numberString = numberString.concat("twenty");
|
|
||||||
}
|
}
|
||||||
number -= (tensPlace * 10);
|
number -= (tensPlace * 10);
|
||||||
//If there is something left in the number you will need a dash to separate the tens and ones place
|
//If there is something left in the number you will need a dash to separate the tens and ones place
|
||||||
if(number > 0){
|
if(number > 0){
|
||||||
numberString = numberString.concat("-");
|
numberString = numberString.append("-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Check for teens
|
//Check for teens
|
||||||
else if((number / 10D) >= 1D){
|
else if((number / 10D) >= 1D){
|
||||||
int onesPlace = (number % 10);
|
int onesPlace = (number % 10);
|
||||||
if(onesPlace == 9){
|
switch(onesPlace){
|
||||||
numberString = numberString.concat("nineteen");
|
case 9: numberString.append("nineteen"); break;
|
||||||
}
|
case 8: numberString.append("eighteen"); break;
|
||||||
else if(onesPlace == 8){
|
case 7: numberString.append("seventeen"); break;
|
||||||
numberString = numberString.concat("eighteen");
|
case 6: numberString.append("sixteen"); break;
|
||||||
}
|
case 5: numberString.append("fifteen"); break;
|
||||||
else if(onesPlace == 7){
|
case 4: numberString.append("fourteen"); break;
|
||||||
numberString = numberString.concat("seventeen");
|
case 3: numberString.append("thirteen"); break;
|
||||||
}
|
case 2: numberString.append("twelve"); break;
|
||||||
else if(onesPlace == 6){
|
case 1: numberString.append("eleven"); break;
|
||||||
numberString = numberString.concat("sixteen");
|
case 0: numberString.append("ten"); break;
|
||||||
}
|
|
||||||
else if(onesPlace == 5){
|
|
||||||
numberString = numberString.concat("fifteen");
|
|
||||||
}
|
|
||||||
else if(onesPlace == 4){
|
|
||||||
numberString = numberString.concat("fourteen");
|
|
||||||
}
|
|
||||||
else if(onesPlace == 3){
|
|
||||||
numberString = numberString.concat("thirteen");
|
|
||||||
}
|
|
||||||
else if(onesPlace == 2){
|
|
||||||
numberString = numberString.concat("twelve");
|
|
||||||
}
|
|
||||||
else if(onesPlace == 1){
|
|
||||||
numberString = numberString.concat("eleven");
|
|
||||||
}
|
|
||||||
else if(onesPlace == 0){
|
|
||||||
numberString = numberString.concat("ten");
|
|
||||||
}
|
}
|
||||||
//If this was hit the number was completed
|
//If this was hit the number was completed
|
||||||
number = 0;
|
number = 0;
|
||||||
@@ -179,39 +147,23 @@ public class Problem17 extends Problem{
|
|||||||
|
|
||||||
//Check for the ones place
|
//Check for the ones place
|
||||||
if(number >= 1){
|
if(number >= 1){
|
||||||
if(number == 9){
|
switch(number){
|
||||||
numberString = numberString.concat("nine");
|
case 9: numberString.append("nine"); break;
|
||||||
}
|
case 8: numberString.append("eight"); break;
|
||||||
else if(number == 8){
|
case 7: numberString.append("seven"); break;
|
||||||
numberString = numberString.concat("eight");
|
case 6: numberString.append("six"); break;
|
||||||
}
|
case 5: numberString.append("five"); break;
|
||||||
else if(number == 7){
|
case 4: numberString.append("four"); break;
|
||||||
numberString = numberString.concat("seven");
|
case 3: numberString.append("three"); break;
|
||||||
}
|
case 2: numberString.append("two"); break;
|
||||||
else if(number == 6){
|
case 1: numberString.append("one"); break;
|
||||||
numberString = numberString.concat("six");
|
|
||||||
}
|
|
||||||
else if(number == 5){
|
|
||||||
numberString = numberString.concat("five");
|
|
||||||
}
|
|
||||||
else if(number == 4){
|
|
||||||
numberString = numberString.concat("four");
|
|
||||||
}
|
|
||||||
else if(number == 3){
|
|
||||||
numberString = numberString.concat("three");
|
|
||||||
}
|
|
||||||
else if(number == 2){
|
|
||||||
numberString = numberString.concat("two");
|
|
||||||
}
|
|
||||||
else if(number == 1){
|
|
||||||
numberString = numberString.concat("one");
|
|
||||||
}
|
}
|
||||||
//If this was hit the number was completed
|
//If this was hit the number was completed
|
||||||
number = 0;
|
number = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return the string
|
//Return the string
|
||||||
return numberString;
|
return numberString.toString();
|
||||||
}
|
}
|
||||||
//This counts the number of letters in the string that is passed in (ignoring numbers and punctuation)
|
//This counts the number of letters in the string that is passed in (ignoring numbers and punctuation)
|
||||||
private int getNumberChars(String number){
|
private int getNumberChars(String number){
|
||||||
|
|||||||
@@ -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-18-20
|
//Modified: 08-26-20
|
||||||
//Find the maximum total from top to bottom
|
//Find the maximum total from top to bottom
|
||||||
/*
|
/*
|
||||||
75
|
75
|
||||||
@@ -180,10 +180,10 @@ public class Problem18 extends Problem{
|
|||||||
//Get the correct total which will be the inversion of the current one
|
//Get the correct total which will be the inversion of the current one
|
||||||
int actualTotal = ((100 * list.size()) - foundPoints.get(foundPoints.size() - 1).total);
|
int actualTotal = ((100 * list.size()) - foundPoints.get(foundPoints.size() - 1).total);
|
||||||
|
|
||||||
result = String.format("The value of the longest path is " + actualTotal);
|
|
||||||
|
|
||||||
//Throw a flag to show the problem is solved
|
//Throw a flag to show the problem is solved
|
||||||
solved = true;
|
solved = true;
|
||||||
|
|
||||||
|
result = String.format("The value of the longest path is " + actualTotal);
|
||||||
}
|
}
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public void reset(){
|
public void reset(){
|
||||||
|
|||||||
@@ -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-10-20
|
//Modified: 08-26-20
|
||||||
//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.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//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-18-20
|
//Modified: 08-26-20
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user