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
|
//Functions
|
||||||
//Constructor
|
//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;
|
sumOfDiagonals = 0;
|
||||||
}
|
}
|
||||||
//Operational functions
|
//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
|
private const long POWER_RAISED = 5; //Starts with 2 because 0 and 1 don't count
|
||||||
//Instance variables
|
//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 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
|
//Gets
|
||||||
public long TopNum{
|
public long TopNum{
|
||||||
get{
|
get{
|
||||||
@@ -65,7 +66,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
if(!solved){
|
if(!solved){
|
||||||
throw new Unsolved();
|
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
|
//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."){
|
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>();
|
SumOfFifthNumbers = new List<long>();
|
||||||
|
sum = 0;
|
||||||
}
|
}
|
||||||
//Operational functions
|
//Operational functions
|
||||||
//Returns an ArrayList with the individual digits of the number passed to it
|
//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
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -123,6 +127,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
public override void Reset(){
|
public override void Reset(){
|
||||||
base.Reset();
|
base.Reset();
|
||||||
SumOfFifthNumbers.Clear();
|
SumOfFifthNumbers.Clear();
|
||||||
|
sum = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user