mirror of
https://bitbucket.org/Mattrixwv/projecteulercs.git
synced 2025-12-06 17:23:57 -05:00
Updated Algorithms
This commit is contained in:
@@ -59,7 +59,7 @@ namespace ProjectEulerCS.Problems{
|
||||
|
||||
//Functions
|
||||
//Constructor
|
||||
public Problem28() : base("What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral"){
|
||||
public Problem28() : base("What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction?"){
|
||||
sumOfDiagonals = 0;
|
||||
}
|
||||
//Operational functions
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace ProjectEulerCS.Problems{
|
||||
private const long POWER_RAISED = 5; //Starts with 2 because 0 and 1 don't count
|
||||
//Instance variables
|
||||
private readonly List<long> SumOfFifthNumbers; //This is an ArrayList of the numbers that are the sum of the fifth power of their digits
|
||||
private long sum; //This is the sum of the sumOfFifthNumbers array
|
||||
//Gets
|
||||
public long TopNum{
|
||||
get{
|
||||
@@ -65,7 +66,7 @@ namespace ProjectEulerCS.Problems{
|
||||
if(!solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
return $"The sum of all the numbers that can be written as the sum of the fifth powers of their digits is {GetSumOfList}";
|
||||
return $"The sum of all the numbers that can be written as the sum of the fifth powers of their digits is {sum}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +74,7 @@ namespace ProjectEulerCS.Problems{
|
||||
//Operational functions
|
||||
public Problem30() : base("Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits."){
|
||||
SumOfFifthNumbers = new List<long>();
|
||||
sum = 0;
|
||||
}
|
||||
//Operational functions
|
||||
//Returns an ArrayList with the individual digits of the number passed to it
|
||||
@@ -113,6 +115,8 @@ namespace ProjectEulerCS.Problems{
|
||||
}
|
||||
}
|
||||
|
||||
sum = GetSumOfList;
|
||||
|
||||
//Stop the timer
|
||||
timer.Stop();
|
||||
|
||||
@@ -123,6 +127,7 @@ namespace ProjectEulerCS.Problems{
|
||||
public override void Reset(){
|
||||
base.Reset();
|
||||
SumOfFifthNumbers.Clear();
|
||||
sum = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user