diff --git a/ProjectEulerCS/Problems/Problem16.cs b/ProjectEulerCS/Problems/Problem16.cs index bf77139..496aa2e 100644 --- a/ProjectEulerCS/Problems/Problem16.cs +++ b/ProjectEulerCS/Problems/Problem16.cs @@ -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 diff --git a/ProjectEulerCS/Problems/Problem6.cs b/ProjectEulerCS/Problems/Problem6.cs index 4599780..7808163 100644 --- a/ProjectEulerCS/Problems/Problem6.cs +++ b/ProjectEulerCS/Problems/Problem6.cs @@ -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(){ diff --git a/ProjectEulerCS/Problems/Problem8.cs b/ProjectEulerCS/Problems/Problem8.cs index 0749e1e..97d328e 100644 --- a/ProjectEulerCS/Problems/Problem8.cs +++ b/ProjectEulerCS/Problems/Problem8.cs @@ -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){ diff --git a/ProjectEulerCS/Problems/Problem9.cs b/ProjectEulerCS/Problems/Problem9.cs index b16b3b7..dc72426 100644 --- a/ProjectEulerCS/Problems/Problem9.cs +++ b/ProjectEulerCS/Problems/Problem9.cs @@ -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{