mirror of
https://bitbucket.org/Mattrixwv/projecteulercs.git
synced 2025-12-06 17:23:57 -05:00
Updated to better match C# standards
This commit is contained in:
@@ -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<int> divisorSum; //Holds the sum of the divisors of the subscript number
|
||||
private List<int> amicable; //Holds all amicable numbers
|
||||
private readonly List<int> divisorSum; //Holds the sum of the divisors of the subscript number
|
||||
private readonly List<int> amicable; //Holds all amicable numbers
|
||||
public List<int> 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<int>();
|
||||
amicable = new List<int>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<long> sums; //Holds the score based on the sum of the characters in the name
|
||||
private List<long> prod; //Holds the score based on the sum of the characters and the location in alphabetical order
|
||||
private readonly List<long> sums; //Holds the score based on the sum of the characters in the name
|
||||
private readonly List<long> 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<string> Names{
|
||||
get{
|
||||
|
||||
@@ -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<int> divisorSums; //This gives the sum of the divisors at subscripts
|
||||
private readonly List<int> 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<int>();
|
||||
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<int> abund, int num){
|
||||
int sum = 0;
|
||||
private bool IsSum(List<int> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string> permutations; //Holds all of the permutations of the string nums
|
||||
public List<string> PermutationsList{
|
||||
|
||||
Reference in New Issue
Block a user