diff --git a/ProjectEulerCS/Problems/Problem1.cs b/ProjectEulerCS/Problems/Problem1.cs index 35b9e41..2d0c8ab 100644 --- a/ProjectEulerCS/Problems/Problem1.cs +++ b/ProjectEulerCS/Problems/Problem1.cs @@ -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 diff --git a/ProjectEulerCS/Problems/Problem10.cs b/ProjectEulerCS/Problems/Problem10.cs index 9cd0da4..d2e8ed5 100644 --- a/ProjectEulerCS/Problems/Problem10.cs +++ b/ProjectEulerCS/Problems/Problem10.cs @@ -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 */ diff --git a/ProjectEulerCS/Problems/Problem11.cs b/ProjectEulerCS/Problems/Problem11.cs index 7848350..f2c1513 100644 --- a/ProjectEulerCS/Problems/Problem11.cs +++ b/ProjectEulerCS/Problems/Problem11.cs @@ -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)}]"; } } diff --git a/ProjectEulerCS/Problems/Problem12.cs b/ProjectEulerCS/Problems/Problem12.cs index 59bc6ab..a821352 100644 --- a/ProjectEulerCS/Problems/Problem12.cs +++ b/ProjectEulerCS/Problems/Problem12.cs @@ -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 */ diff --git a/ProjectEulerCS/Problems/Problem13.cs b/ProjectEulerCS/Problems/Problem13.cs index b6fce2f..f906b60 100644 --- a/ProjectEulerCS/Problems/Problem13.cs +++ b/ProjectEulerCS/Problems/Problem13.cs @@ -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)}"; } } diff --git a/ProjectEulerCS/Problems/Problem14.cs b/ProjectEulerCS/Problems/Problem14.cs index 134b8af..07dfc1d 100644 --- a/ProjectEulerCS/Problems/Problem14.cs +++ b/ProjectEulerCS/Problems/Problem14.cs @@ -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; } diff --git a/ProjectEulerCS/Problems/Problem15.cs b/ProjectEulerCS/Problems/Problem15.cs index 13b20ae..910b2ad 100644 --- a/ProjectEulerCS/Problems/Problem15.cs +++ b/ProjectEulerCS/Problems/Problem15.cs @@ -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}"; } } diff --git a/ProjectEulerCS/Problems/Problem16.cs b/ProjectEulerCS/Problems/Problem16.cs index 4cd1fe4..3cfb0be 100644 --- a/ProjectEulerCS/Problems/Problem16.cs +++ b/ProjectEulerCS/Problems/Problem16.cs @@ -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; } diff --git a/ProjectEulerCS/Problems/Problem17.cs b/ProjectEulerCS/Problems/Problem17.cs index c67c0f3..e3b55ee 100644 --- a/ProjectEulerCS/Problems/Problem17.cs +++ b/ProjectEulerCS/Problems/Problem17.cs @@ -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 diff --git a/ProjectEulerCS/Problems/Problem18.cs b/ProjectEulerCS/Problems/Problem18.cs index 7535931..834306a 100644 --- a/ProjectEulerCS/Problems/Problem18.cs +++ b/ProjectEulerCS/Problems/Problem18.cs @@ -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(); diff --git a/ProjectEulerCS/Problems/Problem19.cs b/ProjectEulerCS/Problems/Problem19.cs index d87eb42..089b4c8 100644 --- a/ProjectEulerCS/Problems/Problem19.cs +++ b/ProjectEulerCS/Problems/Problem19.cs @@ -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 diff --git a/ProjectEulerCS/Problems/Problem2.cs b/ProjectEulerCS/Problems/Problem2.cs index e83e592..3ecc0fb 100644 --- a/ProjectEulerCS/Problems/Problem2.cs +++ b/ProjectEulerCS/Problems/Problem2.cs @@ -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 diff --git a/ProjectEulerCS/Problems/Problem20.cs b/ProjectEulerCS/Problems/Problem20.cs index af29e8a..59b148a 100644 --- a/ProjectEulerCS/Problems/Problem20.cs +++ b/ProjectEulerCS/Problems/Problem20.cs @@ -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; } diff --git a/ProjectEulerCS/Problems/Problem3.cs b/ProjectEulerCS/Problems/Problem3.cs index 61a708a..40c2468 100644 --- a/ProjectEulerCS/Problems/Problem3.cs +++ b/ProjectEulerCS/Problems/Problem3.cs @@ -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(); } //Operational functions diff --git a/ProjectEulerCS/Problems/Problem4.cs b/ProjectEulerCS/Problems/Problem4.cs index aa52c6b..70d9622 100644 --- a/ProjectEulerCS/Problems/Problem4.cs +++ b/ProjectEulerCS/Problems/Problem4.cs @@ -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]}"; } } diff --git a/ProjectEulerCS/Problems/Problem5.cs b/ProjectEulerCS/Problems/Problem5.cs index 882b7ea..8fa08cb 100644 --- a/ProjectEulerCS/Problems/Problem5.cs +++ b/ProjectEulerCS/Problems/Problem5.cs @@ -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}"; } } diff --git a/ProjectEulerCS/Problems/Problem6.cs b/ProjectEulerCS/Problems/Problem6.cs index 7615055..8124cb0 100644 --- a/ProjectEulerCS/Problems/Problem6.cs +++ b/ProjectEulerCS/Problems/Problem6.cs @@ -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; } diff --git a/ProjectEulerCS/Problems/Problem7.cs b/ProjectEulerCS/Problems/Problem7.cs index bc8ebb2..42c0d6a 100644 --- a/ProjectEulerCS/Problems/Problem7.cs +++ b/ProjectEulerCS/Problems/Problem7.cs @@ -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(); } //Operatinal functions diff --git a/ProjectEulerCS/Problems/Problem8.cs b/ProjectEulerCS/Problems/Problem8.cs index dd9f934..49ae650 100644 --- a/ProjectEulerCS/Problems/Problem8.cs +++ b/ProjectEulerCS/Problems/Problem8.cs @@ -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}"; } } diff --git a/ProjectEulerCS/Problems/Problem9.cs b/ProjectEulerCS/Problems/Problem9.cs index 365eef9..2acebbc 100644 --- a/ProjectEulerCS/Problems/Problem9.cs +++ b/ProjectEulerCS/Problems/Problem9.cs @@ -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;