diff --git a/ProjectEulerCS/Problems/Problem21.cs b/ProjectEulerCS/Problems/Problem21.cs index e9c8213..10d425c 100644 --- a/ProjectEulerCS/Problems/Problem21.cs +++ b/ProjectEulerCS/Problems/Problem21.cs @@ -31,8 +31,8 @@ namespace ProjectEulerCS.Problems{ //Static variables private const int LIMIT = 10000; //The number that is > the largest number to be checked //Instance variables - private List divisorSum; //Holds the sum of the divisors of the subscript number - private List amicable; //Holds all amicable numbers + private readonly List divisorSum; //Holds the sum of the divisors of the subscript number + private readonly List amicable; //Holds all amicable numbers public List Amicable{ get{ if(!solved){ @@ -68,11 +68,11 @@ namespace ProjectEulerCS.Problems{ public Problem21() : base($"Evaluate the sum of all the amicable numbers under {LIMIT}"){ divisorSum = new List(); amicable = new List(); - reserveArray(); + ReserveArray(); } //Operational functions //Reserve the size of the array to speed up insertion - private void reserveArray(){ + private void ReserveArray(){ divisorSum.Capacity = LIMIT; //Reserving it now makes it faster later //Make sure the list is filled with 0's while(divisorSum.Count < LIMIT){ @@ -129,7 +129,7 @@ namespace ProjectEulerCS.Problems{ base.Reset(); divisorSum.Clear(); amicable.Clear(); - reserveArray(); + ReserveArray(); } } } diff --git a/ProjectEulerCS/Problems/Problem22.cs b/ProjectEulerCS/Problems/Problem22.cs index e779ed3..116f3a6 100644 --- a/ProjectEulerCS/Problems/Problem22.cs +++ b/ProjectEulerCS/Problems/Problem22.cs @@ -400,8 +400,8 @@ namespace ProjectEulerCS.Problems{ "KENETH","JACINTO","GRAIG","FRANKLYN","EDMUNDO","SID","PORTER","LEIF","JERAMY","BUCK","WILLIAN","VINCENZO","SHON","LYNWOOD","JERE", "HAI","ELDEN","DORSEY","DARELL","BRODERICK","ALONSO"}; //Instance variables - private List sums; //Holds the score based on the sum of the characters in the name - private List prod; //Holds the score based on the sum of the characters and the location in alphabetical order + private readonly List sums; //Holds the score based on the sum of the characters in the name + private readonly List prod; //Holds the score based on the sum of the characters and the location in alphabetical order private long sum; //Holds the sum of the scores public List Names{ get{ diff --git a/ProjectEulerCS/Problems/Problem23.cs b/ProjectEulerCS/Problems/Problem23.cs index 6f313d9..392791f 100644 --- a/ProjectEulerCS/Problems/Problem23.cs +++ b/ProjectEulerCS/Problems/Problem23.cs @@ -31,7 +31,7 @@ namespace ProjectEulerCS.Problems{ //Static variables private const int MAX_NUM = 28123; //THe largest number to be checked //Instance variables - private List divisorSums; //This gives the sum of the divisors at subscripts + private readonly List divisorSums; //This gives the sum of the divisors at subscripts private long sum; //The sum of all the numbers we are looking for public override string Result{ get{ @@ -54,12 +54,12 @@ namespace ProjectEulerCS.Problems{ //Constructor public Problem23() : base("Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers"){ divisorSums = new List(); - reserveArray(); + ReserveArray(); sum = 0; } //Operational functions //Reserve the size of the array to speed up insertion - private void reserveArray(){ + private void ReserveArray(){ divisorSums.Capacity = MAX_NUM; //It is faster to reserve the appropriate amount of ram now //Make sure every element has a 0 in it's location while(divisorSums.Count <= MAX_NUM){ @@ -96,7 +96,7 @@ namespace ProjectEulerCS.Problems{ //Check if each number can be the sum of 2 abundant numbers and add to the sum if no for(int cnt = 1;cnt < MAX_NUM;++cnt){ - if(!isSum(abund, cnt)){ + if(!IsSum(abund, cnt)){ sum += cnt; } } @@ -108,8 +108,8 @@ namespace ProjectEulerCS.Problems{ solved = true; } //A function that returns true if num can be created by adding two elements from abund and false if it cannot - private bool isSum(List abund, int num){ - int sum = 0; + private bool IsSum(List abund, int num){ + int sum; //Pick a number for the first part of the sum for(int firstNum = 0;firstNum < abund.Count;++firstNum){ //Pick a number for the second part of the sum @@ -130,7 +130,7 @@ namespace ProjectEulerCS.Problems{ public override void Reset(){ base.Reset(); divisorSums.Clear(); - reserveArray(); + ReserveArray(); sum = 0; } } diff --git a/ProjectEulerCS/Problems/Problem24.cs b/ProjectEulerCS/Problems/Problem24.cs index 1106175..70dfa5b 100644 --- a/ProjectEulerCS/Problems/Problem24.cs +++ b/ProjectEulerCS/Problems/Problem24.cs @@ -30,7 +30,7 @@ namespace ProjectEulerCS.Problems{ //Variables //Static variables private const int NEEDED_PERM = 1000000; //The number of the permutation that you need - private static string nums = "0123456789"; //All of the characters that we need to get the permutations of + private const string nums = "0123456789"; //All of the characters that we need to get the permutations of //Instance variables private List permutations; //Holds all of the permutations of the string nums public List PermutationsList{