Changed string formatting for description and results

This commit is contained in:
2020-08-28 11:06:44 -04:00
parent b307880181
commit 8c6329a3fb
20 changed files with 34 additions and 34 deletions

View File

@@ -44,13 +44,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The sum of all numbers < %d is %d", (TOP_NUM + 1), fullSum);
return $"The sum of all numbers < {TOP_NUM + 1} is {fullSum}";
}
}
//Functions
//Constructor
public Problem1() : base(string.Format("What is the sum of all the multiples of 3 or 5 that are less than %d", TOP_NUM + 1)){
public Problem1() : base($"What is the sum of all the multiples of 3 or 5 that are less than {TOP_NUM + 1}"){
fullSum = 0;
}
//Operational functions

View File

@@ -47,13 +47,13 @@ namespace ProjectEulerCS{
if(!solved){
throw new Unsolved();
}
return string.Format("The sum of all the primes < %d is %d", (GOAL_NUMBER + 1), sum);
return $"The sum of all the primes < {GOAL_NUMBER + 1} is {sum}";
}
}
//Functions
//Constructor
public Problem10() : base(string.Format("Find the sum of all the primes below %d.", GOAL_NUMBER + 1)){
public Problem10() : base($"Find the sum of all the primes below {GOAL_NUMBER + 1}."){
sum = 0;
}
//Operational functions
@@ -85,6 +85,6 @@ namespace ProjectEulerCS{
}
/* Results:
The sum of all the primes < 1999999 is 142913828922
The sum of all the primes < 2000000 is 142913828922
It took an average of 165.413 milliseconds to run this problem through 100 iterations
*/

View File

@@ -98,7 +98,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The greatestProduct of 4 numbers in a list is %d\nThe numbers are [%s]", mee.Algorithms.GetProd(greatestProduct), string.Join(", ", greatestProduct));
return $"The greatest product of 4 numbers in a line is {mee.Algorithms.GetProd(greatestProduct)}\nThe numbers are [{string.Join(", ", greatestProduct)}]";
}
}

View File

@@ -74,7 +74,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The triangular number %d is the sum of all numbers >= %d and has %d divisors", sum, (counter - 1), divisors.Count);
return $"The triangular number {sum} is the sum of all numbers >= {counter - 1} and has {divisors.Count} divisors";
}
}
@@ -130,6 +130,6 @@ namespace ProjectEulerCS.Problems{
}
/* Results:
The triangular number 76576500 is the sum of all number >= 12375 and has 576 divisors
The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors
It took an average of 270.496 milliseconds to run this problem through 100 iterations
*/

View File

@@ -157,7 +157,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The sum of all %d numbers is %d\nThe first 10 digits of the sum of the numbers is %d", nums.Count, sum, sum.ToString().Substring(0, 10));
return $"The sum of all {nums.Count} numbers is {sum}\nThe first 10 digits of the sum of the numbers is {sum.ToString().Substring(0, 10)}";
}
}

View File

@@ -57,13 +57,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The number %d producted a chain of %d steps", maxNum, maxLength);
return $"The number {maxNum} produced a chain of {maxLength} steps";
}
}
//Functions
//Constructor
public Problem14() : base(string.Format("Which starting number, under %d, produces the longest chain using the itterative sequence?", MAX_NUM + 1)){
public Problem14() : base($"Which starting number, under {MAX_NUM + 1}, produces the longest chain using the itterative sequence?"){
maxLength = 0;
maxNum = 0;
}

View File

@@ -45,7 +45,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The number of routes is %d", numOfRoutes);
return $"The number of routes is {numOfRoutes}";
}
}

View File

@@ -58,13 +58,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("%d^%d = %d\nThe sum of the elements is %d", NUM_TO_POWER, POWER, num, sumOfElements);
return $"{NUM_TO_POWER}^{POWER} = {num}\nThe sum of the elements is {sumOfElements}";
}
}
//Functions
//Constructor
public Problem16() : base(string.Format("What is the sum of the digits of the number %d^%d?", NUM_TO_POWER, POWER)){
public Problem16() : base($"What is the sum of the digits of the number {NUM_TO_POWER}^{POWER}?"){
num = 0;
sumOfElements = 0;
}

View File

@@ -48,13 +48,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The sum of all the letters in all the numbers %d-%d is %d", START_NUM, STOP_NUM, letterCounter);
return $"The sum of all the letters in all the numbers {START_NUM}-{STOP_NUM} is {letterCounter}";
}
}
//Functions
//Constructor
public Problem17() : base(string.Format("If all the numbers from %d to %d inclusive were written out in words, how many letters would be used?", START_NUM, STOP_NUM)){
public Problem17() : base($"If all the numbers from {START_NUM} to {STOP_NUM} inclusive were written out in words, how many letters would be used?"){
letterCounter = 0;
}
//Operational functions

View File

@@ -67,7 +67,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The value of the longest path is %d", actualTotal);
return $"The value of the longest path is {actualTotal}";
}
}
@@ -259,7 +259,7 @@ namespace ProjectEulerCS.Problems{
//Save the results
//Get the correct total which will be the inversion of the current one
int actualTotal = ((100 * list.Count) - foundPoints[^1].Total);
actualTotal = ((100 * list.Count) - foundPoints[^1].Total);
//Stop the timer
timer.Stop();

View File

@@ -53,7 +53,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("There are %d Sundays that landed ont he first of the months from %d to %d", totalSundays, START_YEAR, END_YEAR);
return $"There are {totalSundays} Sundays that landed on the first of the months from {START_YEAR} to {END_YEAR}";
}
}
//Functions

View File

@@ -48,13 +48,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The sum of all even fibonacci numbers <= %d is %d", TOP_NUM, fullSum);
return $"The sum of all even fibonacci numbers <= {TOP_NUM} is {fullSum}";
}
}
//Functions
//Constructor
public Problem2() : base(string.Format("What is the sum of the even Fibonacci numbers less than %d?", TOP_NUM + 1)){
public Problem2() : base($"What is the sum of the even Fibonacci numbers less than {TOP_NUM + 1}?"){
fullSum = 0;
}
//Operational functions

View File

@@ -64,13 +64,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("%d! = %d\nThe sum of the digits is: %d", TOP_NUM, num, sum);
return $"{TOP_NUM}! = {num}\nThe sum of the digits is: {sum}";
}
}
//Functions
//Constructor
public Problem20() : base(string.Format("What is the sum of the digits of %d!?", TOP_NUM)){
public Problem20() : base($"What is the sum of the digits of {TOP_NUM}!?"){
num = 1;
sum = 0;
}

View File

@@ -58,12 +58,12 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The largest factor of the number %d is %d", GOAL_NUMBER, factors[^1]);
return $"The largest factor of the number {GOAL_NUMBER} is {factors[^1]}";
}
}
//Functions
//Constructor
public Problem3() : base(string.Format("What is the largest prime factor of %d?", GOAL_NUMBER)){
public Problem3() : base($"What is the largest prime factor of {GOAL_NUMBER}?"){
factors = new List<long>();
}
//Operational functions

View File

@@ -57,7 +57,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The largest palindrome is %d", palindromes[^1]);
return $"The largest palindrome is {palindromes[^1]}";
}
}

View File

@@ -42,7 +42,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The smallest positive number evenly divisible by all numbers 1-20 is %d", smallestNum);
return $"The smallest positive number evenly divisible by all numbers 1-20 is {smallestNum}";
}
}

View File

@@ -65,12 +65,12 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is %d", Math.Abs(sumOfSquares - squareOfSum));
return $"The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is {Math.Abs(sumOfSquares - squareOfSum)}";
}
}
//Functions
//Constructor
public Problem6() : base(string.Format("Find the difference between the sum of the squares and the square of the sum of the numbers %d-%d.", START_NUM, END_NUM)){
public Problem6() : base($"Find the difference between the sum of the squares and the square of the sum of the numbers {START_NUM}-{END_NUM}."){
sumOfSquares = 0;
squareOfSum = 0;
}

View File

@@ -47,13 +47,13 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The %dth prime number is %d", NUMBER_OF_PRIMES, primes[^1]);
return $"The {NUMBER_OF_PRIMES}th prime number is {primes[^1]}";
}
}
//Functions
//Constructor
public Problem7() : base(string.Format("What is the %dth prime number?", NUMBER_OF_PRIMES)){
public Problem7() : base($"What is the {NUMBER_OF_PRIMES}th prime number?"){
primes = new List<long>();
}
//Operatinal functions

View File

@@ -79,7 +79,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return string.Format("The greatest product is %d\nThe numbers are %d", maxProduct, maxNums);
return $"The greatest product is {maxProduct}\nThe numbers are {maxNums}";
}
}

View File

@@ -74,12 +74,12 @@ namespace ProjectEulerCS{
if(!solved){
throw new Unsolved();
}
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 $"The Pythagorean triplet is {a} + {b} + {Math.Round(c)}\nThe numbers' product is {a * b * Math.Round(c)}";
}
}
//Functions
//Constrcutor
public Problem9() : base(string.Format("There exists exactly one Pythagorean triplet for which a + b + c = %d. Find the product abc.", GOAL_SUM)){
public Problem9() : base($"There exists exactly one Pythagorean triplet for which a + b + c = {GOAL_SUM}. Find the product abc."){
a = 1;
b = 0;
c = 0;