Updated to use more standard C# syntax

This commit is contained in:
2020-08-25 10:41:41 -04:00
parent c68902f2c9
commit 257e32be6b
4 changed files with 17 additions and 7 deletions

View File

@@ -22,6 +22,7 @@
*/
using System;
using System.Numerics;
@@ -76,7 +77,7 @@ namespace ProjectEulerCS.Problems{
//Add up the individual characters of the string
for(int cnt = 0;cnt < numString.Length;++cnt){
sumOfElements += System.Convert.ToInt32(numString.Substring(cnt, 1));
sumOfElements += Convert.ToInt32(numString.Substring(cnt, 1));
}
//Stop the timer

View File

@@ -22,6 +22,9 @@
*/
using System;
namespace ProjectEulerCS.Problems{
public class Problem6 : Problem{
//Variables
@@ -52,7 +55,7 @@ namespace ProjectEulerCS.Problems{
if(!solved){
throw new Unsolved();
}
return System.Math.Abs(sumOfSquares - squareOfSum);
return Math.Abs(sumOfSquares - squareOfSum);
}
}
@@ -88,7 +91,7 @@ namespace ProjectEulerCS.Problems{
solved = true;
//Save the results
_result = "The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is " + System.Math.Abs(sumOfSquares - squareOfSum);
_result = "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);
}
//Reset the problem so it can be run again
public override void Reset(){

View File

@@ -44,6 +44,9 @@
*/
using System;
namespace ProjectEulerCS.Problems{
public class Problem8 : Problem{
//Variables
@@ -89,7 +92,7 @@ namespace ProjectEulerCS.Problems{
//Cycle through the string of numbers looking for the maximum product
for(int cnt = 12;cnt < NUMBER.Length;++cnt){
long currentProduct = System.Int64.Parse(NUMBER[cnt - 12].ToString()) * System.Int64.Parse(NUMBER[cnt - 11].ToString()) * System.Int64.Parse(NUMBER[cnt - 10].ToString()) * System.Int64.Parse(NUMBER[cnt - 9].ToString()) * System.Int64.Parse(NUMBER[cnt - 8].ToString()) * System.Int64.Parse(NUMBER[cnt - 7].ToString()) * System.Int64.Parse(NUMBER[cnt - 6].ToString()) * System.Int64.Parse(NUMBER[cnt - 5].ToString()) * System.Int64.Parse(NUMBER[cnt - 4].ToString()) * System.Int64.Parse(NUMBER[cnt - 3].ToString()) * System.Int64.Parse(NUMBER[cnt - 2].ToString()) * System.Int64.Parse(NUMBER[cnt - 1].ToString()) * System.Int64.Parse(NUMBER[cnt].ToString());
long currentProduct = Int64.Parse(NUMBER[cnt - 12].ToString()) * Int64.Parse(NUMBER[cnt - 11].ToString()) * Int64.Parse(NUMBER[cnt - 10].ToString()) * Int64.Parse(NUMBER[cnt - 9].ToString()) * Int64.Parse(NUMBER[cnt - 8].ToString()) * Int64.Parse(NUMBER[cnt - 7].ToString()) * Int64.Parse(NUMBER[cnt - 6].ToString()) * Int64.Parse(NUMBER[cnt - 5].ToString()) * Int64.Parse(NUMBER[cnt - 4].ToString()) * Int64.Parse(NUMBER[cnt - 3].ToString()) * Int64.Parse(NUMBER[cnt - 2].ToString()) * Int64.Parse(NUMBER[cnt - 1].ToString()) * Int64.Parse(NUMBER[cnt].ToString());
//Check if the product is greater than the current maximum
if(currentProduct > maxProduct){

View File

@@ -22,6 +22,9 @@
*/
using System;
namespace ProjectEulerCS{
public class Problem9 : Problem{
//Variables
@@ -85,12 +88,12 @@ namespace ProjectEulerCS{
//Loop through all possible a's
while((a < 1000) && !found){
b = a + 1; //b must be larget than a
c = System.Math.Sqrt((a * a) + (b * b)); //Compute the hyp
c = Math.Sqrt((a * a) + (b * b)); //Compute the hyp
//Loop through all possible b's for this a
while((a + b + c) < 1000){
++b;
c = System.Math.Sqrt((a * a) + (b * b));
c = Math.Sqrt((a * a) + (b * b));
}
//If the sum == 1000 you found the number, otherwise go to the next possible a
@@ -109,7 +112,7 @@ namespace ProjectEulerCS{
solved = true;
if(found){
_result = "The Pythagorean triplet is " + a + " + " + b + " + " + System.Math.Round(c) +
_result = "The Pythagorean triplet is " + a + " + " + b + " + " + Math.Round(c) +
"\nThe numbers' product is " + Product;
}
else{