From e2be18dbaf1ce633ff5eb80bdedb09965f555860 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sat, 3 Oct 2020 12:51:21 -0400 Subject: [PATCH] Fixed code warnings --- ProjectEulerCS/Problems/Problem29.cs | 2 +- ProjectEulerCS/Problems/Problem30.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ProjectEulerCS/Problems/Problem29.cs b/ProjectEulerCS/Problems/Problem29.cs index 488b8d8..bc87820 100644 --- a/ProjectEulerCS/Problems/Problem29.cs +++ b/ProjectEulerCS/Problems/Problem29.cs @@ -35,7 +35,7 @@ namespace ProjectEulerCS.Problems{ private const int BOTTOM_B = 2; //The lowest possible value for b private const int TOP_B = 100; //The highest possible value for b //Instance variables - private List unique; //Holds all unique values generated + private readonly List unique; //Holds all unique values generated //Gets public static int BottomA{ get{ diff --git a/ProjectEulerCS/Problems/Problem30.cs b/ProjectEulerCS/Problems/Problem30.cs index 27fc2a8..206dd35 100644 --- a/ProjectEulerCS/Problems/Problem30.cs +++ b/ProjectEulerCS/Problems/Problem30.cs @@ -34,7 +34,7 @@ namespace ProjectEulerCS.Problems{ private const long BOTTOM_NUM = 2; //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 - private List sumOfFifthNumbers; //This is an ArrayList of the numbers that are the sum of the fifth power of their digits + private readonly List SumOfFifthNumbers; //This is an ArrayList of the numbers that are the sum of the fifth power of their digits //Gets public long TopNum{ get{ @@ -49,7 +49,7 @@ namespace ProjectEulerCS.Problems{ if(!solved){ throw new Unsolved(); } - return sumOfFifthNumbers; + return SumOfFifthNumbers; } } public long GetSumOfList{ @@ -57,7 +57,7 @@ namespace ProjectEulerCS.Problems{ if(!solved){ throw new Unsolved(); } - return mee.Algorithms.GetSum(sumOfFifthNumbers); + return mee.Algorithms.GetSum(SumOfFifthNumbers); } } public override string Result{ @@ -72,11 +72,11 @@ namespace ProjectEulerCS.Problems{ //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."){ - sumOfFifthNumbers = new List(); + SumOfFifthNumbers = new List(); } //Operational functions //Returns an ArrayList with the individual digits of the number passed to it - private List getDigits(long num){ + private List GetDigits(long num){ List listOfDigits = new List(); //This ArrayList holds the individual digits of num //The easiest way to get the individual digits of a number is by converting it to a string string digits = num.ToString(); @@ -100,7 +100,7 @@ namespace ProjectEulerCS.Problems{ //Start with the lowest number and increment until you reach the largest number for(long currentNum = BOTTOM_NUM;currentNum <= TOP_NUM;++currentNum){ //Get the digits of the number - List digits = getDigits(currentNum); + List digits = GetDigits(currentNum); //Get the sum of the powers long sumOfPowers = 0; foreach(long num in digits){ @@ -109,7 +109,7 @@ namespace ProjectEulerCS.Problems{ //Check if the sum of the powers is the same as the number //If it is, add it tot he list, owtherwise continue to the next number if(sumOfPowers == currentNum){ - sumOfFifthNumbers.Add(currentNum); + SumOfFifthNumbers.Add(currentNum); } } @@ -122,7 +122,7 @@ namespace ProjectEulerCS.Problems{ //Reset the problem so it can be run again public override void Reset(){ base.Reset(); - sumOfFifthNumbers.Clear(); + SumOfFifthNumbers.Clear(); } } }