mirror of
https://bitbucket.org/Mattrixwv/projecteulercs.git
synced 2025-12-06 17:23:57 -05:00
Updated problems to match new library layout
This commit is contained in:
@@ -1,8 +1,24 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-14-20
|
// Created: 08-14-20
|
||||||
//Modified: 08-14-20
|
//Modified: 07-05-21
|
||||||
//This is the base class for the rest of the problems
|
//This is the base class for the rest of the problems
|
||||||
|
/*
|
||||||
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace ProjectEulerCS{
|
namespace ProjectEulerCS{
|
||||||
@@ -34,10 +50,17 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Make sure the problem has been solved and throw an exception if not
|
||||||
|
protected void SolvedCheck(string str){
|
||||||
|
if(!solved){
|
||||||
|
throw new Unsolved("You must solve the problem before you can see the " + str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
public Problem(string newDescription){
|
public Problem(string newDescription){
|
||||||
this._description = newDescription;
|
_description = newDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Operations functions
|
//Operations functions
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem1.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem1.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-14-20
|
// Created: 08-14-20
|
||||||
//Modified: 10-26-20
|
//Modified: 07-05-21
|
||||||
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -34,9 +34,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private int fullSum; //The sum of all the numbers
|
private int fullSum; //The sum of all the numbers
|
||||||
public int Sum{
|
public int Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return fullSum;
|
return fullSum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,9 +42,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all numbers < {TOP_NUM + 1} is {fullSum}";
|
return $"The sum of all numbers < {TOP_NUM + 1} is {fullSum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,9 +63,11 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get the sum of the progressions of 3 and 5 and remove the sum of progressions of the overlap
|
//Get the sum of the progressions of 3 and 5 and remove the sum of progressions of the overlap
|
||||||
fullSum = SumOfProgression(3) + SumOfProgression(5) - SumOfProgression(3 * 5);
|
fullSum = SumOfProgression(3) + SumOfProgression(5) - SumOfProgression(3 * 5);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -89,6 +87,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all numbers < 1000 is 233168
|
The sum of all numbers < 1000 is 233168
|
||||||
It took an average of 1.351 microseconds to run this problem through 100 iterations
|
It took an average of 1.351 microseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem10.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem10.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//Find the sum of all the primes below two million
|
//Find the sum of all the primes below two million
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -34,9 +34,7 @@ namespace ProjectEulerCS{
|
|||||||
private long sum; //The sum of all the prime numbers
|
private long sum; //The sum of all the prime numbers
|
||||||
public long Sum{
|
public long Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,9 +42,7 @@ namespace ProjectEulerCS{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all the primes < {GOAL_NUMBER + 1} is {sum}";
|
return $"The sum of all the primes < {GOAL_NUMBER + 1} is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +63,10 @@ namespace ProjectEulerCS{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get the sum of all prime numbers < GOAL_NUMBER
|
//Get the sum of all prime numbers < GOAL_NUMBER
|
||||||
sum = mee.Algorithms.GetPrimes(GOAL_NUMBER).Sum();
|
sum = mee.NumberAlgorithms.GetPrimes(GOAL_NUMBER).Sum();
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -84,6 +82,7 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all the primes < 2000000 is 142913828922
|
The sum of all the primes < 2000000 is 142913828922
|
||||||
It took an average of 165.413 milliseconds to run this problem through 100 iterations
|
It took an average of 165.413 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem11.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem11.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-24-20
|
// Created: 08-24-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
|
//What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
|
||||||
/*
|
/*
|
||||||
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
|
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -77,28 +77,22 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private List<int> greatestProduct; //Holds the largest product we have found so far
|
private List<int> greatestProduct; //Holds the largest product we have found so far
|
||||||
public List<int> Numbers{
|
public List<int> Numbers{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("numbers");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return greatestProduct;
|
return greatestProduct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int Product{
|
public int Product{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("product of the numbers");
|
||||||
throw new Unsolved();
|
return mee.ArrayAlgorithms.GetProd(greatestProduct);
|
||||||
}
|
|
||||||
return mee.Algorithms.GetProd(greatestProduct);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
return $"The greatest product of 4 numbers in a line is {mee.ArrayAlgorithms.GetProd(greatestProduct)}\nThe numbers are [{string.Join(", ", greatestProduct)}]";
|
||||||
}
|
|
||||||
return $"The greatest product of 4 numbers in a line is {mee.Algorithms.GetProd(greatestProduct)}\nThe numbers are [{string.Join(", ", greatestProduct)}]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +115,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Loop through every row and column
|
//Loop through every row and column
|
||||||
for(int row = 0;row < grid.GetLength(0);++row){
|
for(int row = 0;row < grid.GetLength(0);++row){
|
||||||
for(int col = 0;col < grid.GetLength(1);++col){
|
for(int col = 0;col < grid.GetLength(1);++col){
|
||||||
@@ -150,7 +145,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
currentProduct[3] = grid[row, col + 3];
|
currentProduct[3] = grid[row, col + 3];
|
||||||
|
|
||||||
//If the current number's product is greater than the greatest product replace it
|
//If the current number's product is greater than the greatest product replace it
|
||||||
if(mee.Algorithms.GetProd(currentProduct) > mee.Algorithms.GetProd(greatestProduct)){
|
if(mee.ArrayAlgorithms.GetProd(currentProduct) > mee.ArrayAlgorithms.GetProd(greatestProduct)){
|
||||||
greatestProduct = currentProduct.ToList();
|
greatestProduct = currentProduct.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +158,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
currentProduct[3] = grid[row + 3, col];
|
currentProduct[3] = grid[row + 3, col];
|
||||||
|
|
||||||
//If the current number's product is greater than the greatest product replace it
|
//If the current number's product is greater than the greatest product replace it
|
||||||
if(mee.Algorithms.GetProd(currentProduct) > mee.Algorithms.GetProd(greatestProduct)){
|
if(mee.ArrayAlgorithms.GetProd(currentProduct) > mee.ArrayAlgorithms.GetProd(greatestProduct)){
|
||||||
greatestProduct = currentProduct.ToList();
|
greatestProduct = currentProduct.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +171,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
currentProduct[3] = grid[row + 3, col - 3];
|
currentProduct[3] = grid[row + 3, col - 3];
|
||||||
|
|
||||||
//If the current number's product is greater than the greatest product replace it
|
//If the current number's product is greater than the greatest product replace it
|
||||||
if(mee.Algorithms.GetProd(currentProduct) > mee.Algorithms.GetProd(greatestProduct)){
|
if(mee.ArrayAlgorithms.GetProd(currentProduct) > mee.ArrayAlgorithms.GetProd(greatestProduct)){
|
||||||
greatestProduct = currentProduct.ToList();
|
greatestProduct = currentProduct.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,13 +184,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
currentProduct[3] = grid[row + 3, col + 3];
|
currentProduct[3] = grid[row + 3, col + 3];
|
||||||
|
|
||||||
//If the current number's product is greater than the greatest product replace it
|
//If the current number's product is greater than the greatest product replace it
|
||||||
if(mee.Algorithms.GetProd(currentProduct) > mee.Algorithms.GetProd(greatestProduct)){
|
if(mee.ArrayAlgorithms.GetProd(currentProduct) > mee.ArrayAlgorithms.GetProd(greatestProduct)){
|
||||||
greatestProduct = currentProduct.ToList();
|
greatestProduct = currentProduct.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -210,6 +206,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The greatest product of 4 numbers in a line is 70600674
|
The greatest product of 4 numbers in a line is 70600674
|
||||||
The numbers are [89, 94, 97, 87]
|
The numbers are [89, 94, 97, 87]
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem12.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem12.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-24-20
|
// Created: 08-24-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//What is the value of the first triangle number to have over five hundred divisors?
|
//What is the value of the first triangle number to have over five hundred divisors?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -37,33 +37,25 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private List<long> divisors; //Holds the divisors of the triangular number sum
|
private List<long> divisors; //Holds the divisors of the triangular number sum
|
||||||
public long TriangularNumber{
|
public long TriangularNumber{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("triangular number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long LastNumberAdded{
|
public long LastNumberAdded{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("last number added to get the triangular number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return counter - 1;
|
return counter - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<long> DivisorsOfTriangularNumber{
|
public List<long> DivisorsOfTriangularNumber{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("divisors of the triangular number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return divisors;
|
return divisors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int NumberOfDivisors{
|
public int NumberOfDivisors{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number of divisors of the triangular number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return divisors.Count;
|
return divisors.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,9 +63,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The result of the problem
|
//The result of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The triangular number {sum} is the sum of all numbers >= {counter - 1} and has {divisors.Count} divisors";
|
return $"The triangular number {sum} is the sum of all numbers >= {counter - 1} and has {divisors.Count} divisors";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,9 +89,10 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Loop until you fin the appropriate number
|
//Loop until you fin the appropriate number
|
||||||
while((!foundNumber) && (sum > 0)){
|
while((!foundNumber) && (sum > 0)){
|
||||||
divisors = mee.Algorithms.GetDivisors(sum);
|
divisors = mee.NumberAlgorithms.GetDivisors(sum);
|
||||||
//If the number of divisors is correct set the flag
|
//If the number of divisors is correct set the flag
|
||||||
if(divisors.Count > GOAL_DIVISORS){
|
if(divisors.Count > GOAL_DIVISORS){
|
||||||
foundNumber = true;
|
foundNumber = true;
|
||||||
@@ -113,6 +104,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -129,6 +121,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors
|
The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors
|
||||||
It took an average of 270.496 milliseconds to run this problem through 100 iterations
|
It took an average of 270.496 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem13.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem13.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-24-20
|
// Created: 08-24-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
//Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
||||||
/*
|
/*
|
||||||
37107287533902102798797998220837590246510135740250
|
37107287533902102798797998220837590246510135740250
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -135,18 +135,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private readonly List<BigInteger> nums; //The numbers that are being summed
|
private readonly List<BigInteger> nums; //The numbers that are being summed
|
||||||
public List<BigInteger> Numbers{
|
public List<BigInteger> Numbers{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("numbers");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return nums;
|
return nums;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private BigInteger sum; //The sum of all the numbers
|
private BigInteger sum; //The sum of all the numbers
|
||||||
public BigInteger Sum{
|
public BigInteger Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,9 +150,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all {nums.Count} numbers is {sum}\nThe first 10 digits of the sum of the numbers is {sum.ToString().Substring(0, 10)}";
|
return $"The sum of all {nums.Count} numbers is {sum}\nThe first 10 digits of the sum of the numbers is {sum.ToString().Substring(0, 10)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,8 +275,10 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get the sum of all the number
|
//Get the sum of all the number
|
||||||
sum = mee.Algorithms.GetSum(nums);
|
sum = mee.ArrayAlgorithms.GetSum(nums);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -300,6 +296,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672
|
The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672
|
||||||
The first 10 digits of the sum of the numbers is 5537376230
|
The first 10 digits of the sum of the numbers is 5537376230
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem14.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem14.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-24-20
|
// Created: 08-24-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
/*
|
/*
|
||||||
The following iterative sequence is defined for the set of positive integers:
|
The following iterative sequence is defined for the set of positive integers:
|
||||||
n → n/2 (n is even)
|
n → n/2 (n is even)
|
||||||
@@ -10,7 +10,7 @@ Which starting number, under one million, produces the longest chain?
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -36,27 +36,21 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private long maxLength; //This is the length of the longest chain
|
private long maxLength; //This is the length of the longest chain
|
||||||
public long Length{
|
public long Length{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("length of the longest chain");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return maxLength;
|
return maxLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private long maxNum; //This is the starting number of the longest chain
|
private long maxNum; //This is the starting number of the longest chain
|
||||||
public long StartingNumber{
|
public long StartingNumber{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("starting number of the longest chain");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return maxNum;
|
return maxNum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The number {maxNum} produced a chain of {maxLength} steps";
|
return $"The number {maxNum} produced a chain of {maxLength} steps";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,6 +72,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Loop through all numbers <= MAX_NUM and check them against the series
|
//Loop through all numbers <= MAX_NUM and check them against the series
|
||||||
for(long currentNum = 1;currentNum <= MAX_NUM;++currentNum){
|
for(long currentNum = 1;currentNum <= MAX_NUM;++currentNum){
|
||||||
long currentLength = CheckSeries(currentNum);
|
long currentLength = CheckSeries(currentNum);
|
||||||
@@ -88,6 +83,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -121,6 +117,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The number 837799 produced a chain of 525 steps
|
The number 837799 produced a chain of 525 steps
|
||||||
It took an average of 249.883 milliseconds to run this problem through 100 iterations
|
It took an average of 249.883 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem15.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem15.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-25-20
|
// Created: 08-25-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?
|
//How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -32,9 +32,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private long numOfRoutes; //The number of routes from 0, 0 to 20, 20
|
private long numOfRoutes; //The number of routes from 0, 0 to 20, 20
|
||||||
public long NumberOfRoutes{
|
public long NumberOfRoutes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number of routes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return numOfRoutes;
|
return numOfRoutes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,9 +40,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The number of routes is {numOfRoutes}";
|
return $"The number of routes is {numOfRoutes}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,10 +61,12 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//We write this as a recursive function
|
//We write this as a recursive function
|
||||||
//When in a location it always moves right first, then down
|
//When in a location it always moves right first, then down
|
||||||
Move(0, 0);
|
Move(0, 0);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -102,6 +100,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results
|
/* Results
|
||||||
The number of routes is 137846528820
|
The number of routes is 137846528820
|
||||||
It took 17.328 minutes to solve this problem.
|
It took 17.328 minutes to solve this problem.
|
||||||
|
|||||||
@@ -36,18 +36,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private BigInteger num; //The number to be calculated
|
private BigInteger num; //The number to be calculated
|
||||||
public BigInteger Number{
|
public BigInteger Number{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private int sumOfElements; //The sum of all digits in the number
|
private int sumOfElements; //The sum of all digits in the number
|
||||||
public int Sum{
|
public int Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sumOfElements;
|
return sumOfElements;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,9 +51,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"{NUM_TO_POWER}^{POWER} = {num}\nThe sum of the elements is {sumOfElements}";
|
return $"{NUM_TO_POWER}^{POWER} = {num}\nThe sum of the elements is {sumOfElements}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,6 +73,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get the number
|
//Get the number
|
||||||
num = BigInteger.Pow(NUM_TO_POWER, POWER);
|
num = BigInteger.Pow(NUM_TO_POWER, POWER);
|
||||||
|
|
||||||
@@ -90,6 +85,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
sumOfElements += Convert.ToInt32(numString.Substring(cnt, 1));
|
sumOfElements += Convert.ToInt32(numString.Substring(cnt, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -105,6 +101,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
|
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
|
||||||
The sum of the elements is 1366
|
The sum of the elements is 1366
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem17.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem17.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-25-20
|
// Created: 08-25-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
//If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,9 +35,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private long letterCounter; //This is the cumulative number of letters in the words of the numbers
|
private long letterCounter; //This is the cumulative number of letters in the words of the numbers
|
||||||
public long LetterCount{
|
public long LetterCount{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("letter count");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return letterCounter;
|
return letterCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +43,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all the letters in all the numbers {START_NUM}-{STOP_NUM} is {letterCounter}";
|
return $"The sum of all the letters in all the numbers {START_NUM}-{STOP_NUM} is {letterCounter}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,6 +64,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start with 1 and increment
|
//Start with 1 and increment
|
||||||
for(int num = START_NUM;num <= STOP_NUM;++num){
|
for(int num = START_NUM;num <= STOP_NUM;++num){
|
||||||
//Pass the number to a function that will create a string for the number
|
//Pass the number to a function that will create a string for the number
|
||||||
@@ -76,6 +73,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
letterCounter += GetNumberChars(currentNumString);
|
letterCounter += GetNumberChars(currentNumString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -199,6 +197,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Result:
|
/* Result:
|
||||||
The sum of all the letters in all the numbers 1-1000 is 21124
|
The sum of all the letters in all the numbers 1-1000 is 21124
|
||||||
It took an average of 208.222 microseconds to run this problem through 100 iterations
|
It took an average of 208.222 microseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The value of the longest path is {actualTotal}";
|
return $"The value of the longest path is {actualTotal}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,9 +92,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
public string Trail{
|
public string Trail{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("trail of the shortest path");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
|
|
||||||
string results = "";
|
string results = "";
|
||||||
//Save the trail the algorithm took
|
//Save the trail the algorithm took
|
||||||
@@ -151,9 +147,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
public int Total{
|
public int Total{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("total");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return actualTotal;
|
return actualTotal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,6 +206,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Invert the list
|
//Invert the list
|
||||||
Invert(list);
|
Invert(list);
|
||||||
|
|
||||||
@@ -261,6 +256,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Get the correct total which will be the inversion of the current one
|
//Get the correct total which will be the inversion of the current one
|
||||||
actualTotal = ((100 * list.Count) - foundPoints[^1].Total);
|
actualTotal = ((100 * list.Count) - foundPoints[^1].Total);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -277,6 +273,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The value of the longest path is 1074
|
The value of the longest path is 1074
|
||||||
It took an average of 32.856 microseconds to run this problem through 100 iterations
|
It took an average of 32.856 microseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem19.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem19.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-26-20
|
// Created: 08-26-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
//How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
||||||
/*
|
/*
|
||||||
You are given the following information, but you may prefer to do some research for yourself.
|
You are given the following information, but you may prefer to do some research for yourself.
|
||||||
@@ -16,7 +16,7 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -50,9 +50,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"There are {totalSundays} Sundays that landed on the first of the months from {START_YEAR} to {END_YEAR}";
|
return $"There are {totalSundays} Sundays that landed on the first of the months from {START_YEAR} to {END_YEAR}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +70,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Run for all years 1901-2000
|
//Run for all years 1901-2000
|
||||||
for(int year = START_YEAR;year <= END_YEAR;++year){
|
for(int year = START_YEAR;year <= END_YEAR;++year){
|
||||||
//Run for all months in the year
|
//Run for all months in the year
|
||||||
@@ -86,6 +85,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -203,6 +203,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
There are 171 Sundays that landed on the first of the months from 1901 to 2000
|
There are 171 Sundays that landed on the first of the months from 1901 to 2000
|
||||||
It took an average of 6.001 milliseconds to run this problem through 100 iterations
|
It took an average of 6.001 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem2.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem2.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//The sum of the even Fibonacci numbers less than 4,000,000
|
//The sum of the even Fibonacci numbers less than 4,000,000
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,9 +35,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private int fullSum; //Holds the sum of all the numbers
|
private int fullSum; //Holds the sum of all the numbers
|
||||||
public int Sum{
|
public int Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return fullSum;
|
return fullSum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +43,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all even fibonacci numbers <= {TOP_NUM} is {fullSum}";
|
return $"The sum of all even fibonacci numbers <= {TOP_NUM} is {fullSum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,8 +64,9 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get a list of all fibonacci numbers < 4,000,000
|
//Get a list of all fibonacci numbers < 4,000,000
|
||||||
List<int> fibNums = mee.Algorithms.GetAllFib(TOP_NUM);
|
List<int> fibNums = mee.NumberAlgorithms.GetAllFib(TOP_NUM);
|
||||||
//Step through every element in the list checkint if it is even
|
//Step through every element in the list checkint if it is even
|
||||||
foreach(int num in fibNums){
|
foreach(int num in fibNums){
|
||||||
//If the number is even add it to the running tally
|
//If the number is even add it to the running tally
|
||||||
@@ -78,6 +75,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -92,6 +90,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all even fibonacci numbers <= 3999999 is 4613732
|
The sum of all even fibonacci numbers <= 3999999 is 4613732
|
||||||
It took an average of 5.810 microseconds to run this problem through 100 iterations
|
It took an average of 5.810 microseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem20.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem20.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-27-20
|
// Created: 08-27-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//What is the sum of the digits of 100!?
|
//What is the sum of the digits of 100!?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -34,26 +34,20 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private BigInteger num; //Holds the number 100!
|
private BigInteger num; //Holds the number 100!
|
||||||
public BigInteger Number{
|
public BigInteger Number{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string NumberString{
|
public string NumberString{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number as a string");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return num.ToString();
|
return num.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private long sum; //The sum of the digits of num
|
private long sum; //The sum of the digits of num
|
||||||
public long Sum{
|
public long Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of the digits");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,9 +55,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"{TOP_NUM}! = {num}\nThe sum of the digits is: {sum}";
|
return $"{TOP_NUM}! = {num}\nThe sum of the digits is: {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +77,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Run through every number from 1 to 100 and multiply it by the current num to generate 100!
|
//Run through every number from 1 to 100 and multiply it by the current num to generate 100!
|
||||||
for(int cnt = TOP_NUM;cnt > 1;--cnt){
|
for(int cnt = TOP_NUM;cnt > 1;--cnt){
|
||||||
num *= cnt;
|
num *= cnt;
|
||||||
@@ -98,6 +91,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
sum += (long)char.GetNumericValue(digit);
|
sum += (long)char.GetNumericValue(digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -113,6 +107,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
|
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
|
||||||
The sum of the digits is: 648
|
The sum of the digits is: 648
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem21.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem21.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-02-20
|
// Created: 09-02-20
|
||||||
//Modified: 09-02-20
|
//Modified: 07-05-21
|
||||||
//Evaluate the sum of all the amicable numbers under 10000
|
//Evaluate the sum of all the amicable numbers under 10000
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,25 +35,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private readonly List<int> amicable; //Holds all amicable numbers
|
private readonly List<int> amicable; //Holds all amicable numbers
|
||||||
public List<int> Amicable{
|
public List<int> Amicable{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("amicable numbers");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return amicable;
|
return amicable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int Sum{
|
public int Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of the amicable numbers");
|
||||||
throw new Unsolved();
|
return mee.ArrayAlgorithms.GetSum(amicable);
|
||||||
}
|
|
||||||
return mee.Algorithms.GetSum(amicable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
string result = $"All amicable numebrs less than {LIMIT} are\n";
|
string result = $"All amicable numebrs less than {LIMIT} are\n";
|
||||||
foreach (int num in amicable){
|
foreach (int num in amicable){
|
||||||
result += $"{num}\n";
|
result += $"{num}\n";
|
||||||
@@ -89,13 +83,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Generate the divisors of all numbers < 10000, get their sum, and add it to the list
|
//Generate the divisors of all numbers < 10000, get their sum, and add it to the list
|
||||||
for(int cnt = 1;cnt < LIMIT;++cnt){
|
for(int cnt = 1;cnt < LIMIT;++cnt){
|
||||||
List<int> divisors = mee.Algorithms.GetDivisors(cnt); //Get all the divisors of a number
|
List<int> divisors = mee.NumberAlgorithms.GetDivisors(cnt); //Get all the divisors of a number
|
||||||
if(divisors.Count > 1){
|
if(divisors.Count > 1){
|
||||||
divisors.Remove(divisors[^1]); //Remove the last entry because it will be the number itself
|
divisors.Remove(divisors[^1]); //Remove the last entry because it will be the number itself
|
||||||
}
|
}
|
||||||
divisorSum[cnt] = mee.Algorithms.GetSum(divisors); //Add the sum of the divisors of the vector
|
divisorSum[cnt] = mee.ArrayAlgorithms.GetSum(divisors); //Add the sum of the divisors of the vector
|
||||||
}
|
}
|
||||||
//Check every sum of divisors in the list for a matching sum
|
//Check every sum of divisors in the list for a matching sum
|
||||||
for(int cnt = 1;cnt < divisorSum.Count;++cnt){
|
for(int cnt = 1;cnt < divisorSum.Count;++cnt){
|
||||||
@@ -118,6 +113,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Sort the list for neatness
|
//Sort the list for neatness
|
||||||
amicable.Sort();
|
amicable.Sort();
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -134,6 +130,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
All amicable numebrs less than 10000 are
|
All amicable numebrs less than 10000 are
|
||||||
220
|
220
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem22.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem22.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-02-20
|
// Created: 09-02-20
|
||||||
//Modified: 09-02-20
|
//Modified: 07-05-21
|
||||||
//What is the total of all the name scores in this file?
|
//What is the total of all the name scores in this file?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -405,22 +405,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private long sum; //Holds the sum of the scores
|
private long sum; //Holds the sum of the scores
|
||||||
public List<string> Names{
|
public List<string> Names{
|
||||||
get{
|
get{
|
||||||
|
SolvedCheck("names");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long NameScoreSum{
|
public long NameScoreSum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("score of the names");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The answer to the question is {sum}";
|
return $"The answer to the question is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -441,6 +438,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Sort all the names
|
//Sort all the names
|
||||||
names.Sort();
|
names.Sort();
|
||||||
//Step through every name adding up the values of the characters
|
//Step through every name adding up the values of the characters
|
||||||
@@ -458,7 +456,8 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Get the sum of all the numbers
|
//Get the sum of all the numbers
|
||||||
sum = mee.Algorithms.GetSum(prod);
|
sum = mee.ArrayAlgorithms.GetSum(prod);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -476,6 +475,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The answer to the question is 871198282
|
The answer to the question is 871198282
|
||||||
It took an average of 3.180 milliseconds to run this problem through 100 iterations
|
It took an average of 3.180 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem23.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem23.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-03-20
|
// Created: 09-03-20
|
||||||
//Modified: 09-03-20
|
//Modified: 07-05-21
|
||||||
//Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
|
//Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,17 +35,13 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private long sum; //The sum of all the numbers we are looking for
|
private long sum; //The sum of all the numbers we are looking for
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The answer is {sum}";
|
return $"The answer is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long Sum{
|
public long Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,14 +72,15 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get the sum of the divisors of all numbers < MAX_NUM
|
//Get the sum of the divisors of all numbers < MAX_NUM
|
||||||
for(int cnt = 1;cnt < MAX_NUM;++cnt){
|
for(int cnt = 1;cnt < MAX_NUM;++cnt){
|
||||||
List<int> div = mee.Algorithms.GetDivisors(cnt);
|
List<int> div = mee.NumberAlgorithms.GetDivisors(cnt);
|
||||||
//Remove the last element, which is the number itself. This gives us the propper divisors
|
//Remove the last element, which is the number itself. This gives us the propper divisors
|
||||||
if(div.Count > 1){
|
if(div.Count > 1){
|
||||||
div.Remove(div[^1]);
|
div.Remove(div[^1]);
|
||||||
}
|
}
|
||||||
divisorSums[cnt] = mee.Algorithms.GetSum(div);
|
divisorSums[cnt] = mee.ArrayAlgorithms.GetSum(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the abundant numbers
|
//Get the abundant numbers
|
||||||
@@ -101,6 +98,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -136,6 +134,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The answer is 4179871
|
The answer is 4179871
|
||||||
It took an average of 11.420 seconds to run this problem through 100 iterations
|
It took an average of 11.420 seconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem24.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem24.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-03-20
|
// Created: 09-03-20
|
||||||
//Modified: 09-04-20
|
//Modified: 07-05-21
|
||||||
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,25 +35,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private List<string> permutations; //Holds all of the permutations of the string nums
|
private List<string> permutations; //Holds all of the permutations of the string nums
|
||||||
public List<string> PermutationsList{
|
public List<string> PermutationsList{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("permutations");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return permutations;
|
return permutations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string Permutation{
|
public string Permutation{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("1,000,000th permutation");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return permutations[NEEDED_PERM - 1];
|
return permutations[NEEDED_PERM - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The 1 millionth permutation is {Permutation}";
|
return $"The 1 millionth permutation is {Permutation}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,8 +68,10 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get all the permutations of the string
|
//Get all the permutations of the string
|
||||||
permutations = mee.Algorithms.GetPermutations(nums);
|
permutations = mee.StringAlgorithms.GetPermutations(nums);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -91,6 +87,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The 1 millionth permutation is 2783915460
|
The 1 millionth permutation is 2783915460
|
||||||
It took an average of 5.865 seconds to run this problem through 100 iterations
|
It took an average of 5.865 seconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem25.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem25.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-11-20
|
// Created: 09-11-20
|
||||||
//Modified: 09-11-20
|
//Modified: 07-05-21
|
||||||
//What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
|
//What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,25 +35,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private BigInteger index; //The index of the current Fibonacci number just calculated
|
private BigInteger index; //The index of the current Fibonacci number just calculated
|
||||||
public BigInteger Number{
|
public BigInteger Number{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("fibonacci number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public BigInteger Index{
|
public BigInteger Index{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("index of the fibonacci number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The first Fibonacci number with {NUM_DIGITS} digits is {number}\nIts index is {index}";
|
return $"The first Fibonacci number with {NUM_DIGITS} digits is {number}\nIts index is {index}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,12 +69,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Star the timer
|
//Star the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Move through all Fibonacci numbers until you reach the one with at least NUM_DIGITS digits
|
//Move through all Fibonacci numbers until you reach the one with at least NUM_DIGITS digits
|
||||||
while(number.ToString().Length < NUM_DIGITS){
|
while(number.ToString().Length < NUM_DIGITS){
|
||||||
index += 1; //Increase the index number. Doing this at the beginning keeps the index correct at the end of the loop
|
index += 1; //Increase the index number. Doing this at the beginning keeps the index correct at the end of the loop
|
||||||
number = mee.Algorithms.GetFib(index); //Calculate the number
|
number = mee.NumberAlgorithms.GetFib(index); //Calculate the number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -96,6 +92,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
|
The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
|
||||||
Its index is 4782
|
Its index is 4782
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem26.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem26.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-11-20
|
// Created: 09-11-20
|
||||||
//Modified: 09-11-20
|
//Modified: 07-05-21
|
||||||
//Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
//Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,25 +35,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private int longestNumber; //The starting denominator of the longest cycle
|
private int longestNumber; //The starting denominator of the longest cycle
|
||||||
public int LongestCycle{
|
public int LongestCycle{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("length of the longest cycle");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return longestCycle;
|
return longestCycle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int LongestNumber{
|
public int LongestNumber{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("denominator that starts the longest cycle");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return longestNumber;
|
return longestNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The longest cycle is {longestCycle} digits long\nIt started with the number {longestNumber}";
|
return $"The longest cycle is {longestCycle} digits long\nIt started with the number {longestNumber}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +69,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start with 1/2 and find out how long the longest cycle is by checking the remainders
|
//Start with 1/2 and find out how long the longest cycle is by checking the remainders
|
||||||
//Loop through every number from 2-999 and use it for the denominator
|
//Loop through every number from 2-999 and use it for the denominator
|
||||||
for(int denominator = 2;denominator <= TOP_NUM;++denominator){
|
for(int denominator = 2;denominator <= TOP_NUM;++denominator){
|
||||||
@@ -111,6 +106,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -126,6 +122,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The longest cycle is 982 digits long
|
The longest cycle is 982 digits long
|
||||||
It started with the number 983
|
It started with the number 983
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem27.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem27.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-11-20
|
// Created: 09-11-20
|
||||||
//Modified: 09-11-20
|
//Modified: 07-05-21
|
||||||
//Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.
|
//Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -38,33 +38,31 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private List<int> primes; //A list of all primes that could possibly be generated with this formula
|
private List<int> primes; //A list of all primes that could possibly be generated with this formula
|
||||||
public int TOP_A{
|
public int TOP_A{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("largest A");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return topA;
|
return topA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int TOP_B{
|
public int TOP_B{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("largest B");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return topB;
|
return topB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int TOP_N{
|
public int TOP_N{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("largest N");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return topN;
|
return topN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public int Product{
|
||||||
|
get{
|
||||||
|
SolvedCheck("product of A and B");
|
||||||
|
return topA * topB;
|
||||||
|
}
|
||||||
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The greatest number of primes found is {topN}\nIt was found with A = {topA}, B = {topB}\nThe product of A and B is {topA * topB}";
|
return $"The greatest number of primes found is {topN}\nIt was found with A = {topA}, B = {topB}\nThe product of A and B is {topA * topB}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,8 +86,9 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get the primes
|
//Get the primes
|
||||||
primes = mee.Algorithms.GetPrimes(12000);
|
primes = mee.NumberAlgorithms.GetPrimes(12000);
|
||||||
|
|
||||||
//Start with the lowest possible A and check all possibilities after that
|
//Start with the lowest possible A and check all possibilities after that
|
||||||
for(int a = -LARGEST_POSSIBLE_A;a <= LARGEST_POSSIBLE_A;++a){
|
for(int a = -LARGEST_POSSIBLE_A;a <= LARGEST_POSSIBLE_A;++a){
|
||||||
@@ -113,6 +112,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Top the timer
|
//Top the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -130,6 +130,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Result:
|
/* Result:
|
||||||
The greatest number of primes found is 70
|
The greatest number of primes found is 70
|
||||||
It was found with A = -61, B = 971
|
It was found with A = -61, B = 971
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem28.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem28.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 09-21-20
|
// Created: 09-21-20
|
||||||
//Modified: 09-21-20
|
//Modified: 07-05-21
|
||||||
//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
|
//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
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -34,25 +34,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private int sumOfDiagonals; //Holds the sum of the diagonals of the grid
|
private int sumOfDiagonals; //Holds the sum of the diagonals of the grid
|
||||||
public List<List<int>> Grid{
|
public List<List<int>> Grid{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("grid");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int Sum{
|
public int Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sumOfDiagonals;
|
return sumOfDiagonals;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of the diagonals in the given grid is {sumOfDiagonals}";
|
return $"The sum of the diagonals in the given grid is {sumOfDiagonals}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,11 +140,13 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Setup the grid
|
//Setup the grid
|
||||||
SetupGrid();
|
SetupGrid();
|
||||||
//Find the sum of the diagonals in the grid
|
//Find the sum of the diagonals in the grid
|
||||||
FindSum();
|
FindSum();
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -165,6 +161,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of the diagonals in the given grid is 669171001
|
The sum of the diagonals in the given grid is 669171001
|
||||||
It took an average of 7.735 milliseconds to run this problem through 100 iterations
|
It took an average of 7.735 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem29.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem29.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-03-20
|
// Created: 10-03-20
|
||||||
//Modified: 10-03-20
|
//Modified: 07-05-21
|
||||||
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -44,7 +44,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
public static int BottomB{
|
public static int BottomB{
|
||||||
get{
|
get{
|
||||||
return BottomB;
|
return BOTTOM_B;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static int TopA{
|
public static int TopA{
|
||||||
@@ -59,18 +59,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
public List<BigInteger> Unique{
|
public List<BigInteger> Unique{
|
||||||
get{
|
get{
|
||||||
//If the problem hasn't been solved throw an exception
|
SolvedCheck("unique values for a^b");
|
||||||
if(!solved){
|
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return unique;
|
return unique;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public int NumUnique{
|
||||||
|
get{
|
||||||
|
SolvedCheck("number of unique values for a^b");
|
||||||
|
return unique.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The number of unique values generated by a^b for {BOTTOM_A} <= a <= {TOP_A} and {BOTTOM_B} <= b <= {TOP_B} is {unique.Count}";
|
return $"The number of unique values generated by a^b for {BOTTOM_A} <= a <= {TOP_A} and {BOTTOM_B} <= b <= {TOP_B} is {unique.Count}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,6 +92,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start with the first A and move towards the top
|
//Start with the first A and move towards the top
|
||||||
for(int currentA = BOTTOM_A;currentA <= TOP_A;++currentA){
|
for(int currentA = BOTTOM_A;currentA <= TOP_A;++currentA){
|
||||||
//Start with the first B and move towards the top
|
//Start with the first B and move towards the top
|
||||||
@@ -104,6 +106,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -117,6 +120,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
|
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
|
||||||
It took an average of 127.770 milliseconds to run this problem through 100 iterations
|
It took an average of 127.770 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem3.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem3.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//The largest prime factor of 600851475143
|
//The largest prime factor of 600851475143
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -37,17 +37,13 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private List<long> factors; //Holds the factors of goalNumber
|
private List<long> factors; //Holds the factors of goalNumber
|
||||||
public List<long> Factors{
|
public List<long> Factors{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("factors");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return factors;
|
return factors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long LargestFactor{
|
public long LargestFactor{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("largest factor");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return factors[^1];
|
return factors[^1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,9 +51,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The largest factor of the number {GOAL_NUMBER} is {factors[^1]}";
|
return $"The largest factor of the number {GOAL_NUMBER} is {factors[^1]}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,10 +71,12 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Star the timer
|
//Star the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get all the factors of the number
|
//Get all the factors of the number
|
||||||
factors = mee.Algorithms.GetFactors(GOAL_NUMBER);
|
factors = mee.NumberAlgorithms.GetFactors(GOAL_NUMBER);
|
||||||
//THe last element should be the largest factor
|
//THe last element should be the largest factor
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -95,6 +91,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*Results:
|
/*Results:
|
||||||
The largest factor of the number 600851475143 is 6857
|
The largest factor of the number 600851475143 is 6857
|
||||||
It took an average of 47.412 milliseconds to run this problem through 100 iterations
|
It took an average of 47.412 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem30.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem30.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-03-20
|
// Created: 10-03-20
|
||||||
//Modified: 10-03-20
|
//Modified: 07-05-21
|
||||||
//Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.
|
//Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -39,33 +39,25 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Gets
|
//Gets
|
||||||
public long TopNum{
|
public long TopNum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("largest number checked");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return TOP_NUM;
|
return TOP_NUM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<long> ListOfSumOfFifths{
|
public List<long> ListOfSumOfFifths{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("list of all numbers that are the sum of the 5th power of their digits");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return SumOfFifthNumbers;
|
return SumOfFifthNumbers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long GetSumOfList{
|
public long GetSumOfList{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of all numbers that are the sum of the 5th power of their digits");
|
||||||
throw new Unsolved();
|
return sum;
|
||||||
}
|
|
||||||
return mee.Algorithms.GetSum(SumOfFifthNumbers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
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 {sum}";
|
return $"The sum of all the numbers that can be written as the sum of the fifth powers of their digits is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,6 +91,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start with the lowest number and increment until you reach the largest number
|
//Start with the lowest number and increment until you reach the largest number
|
||||||
for(long currentNum = BOTTOM_NUM;currentNum <= TOP_NUM;++currentNum){
|
for(long currentNum = BOTTOM_NUM;currentNum <= TOP_NUM;++currentNum){
|
||||||
//Get the digits of the number
|
//Get the digits of the number
|
||||||
@@ -115,7 +108,8 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sum = GetSumOfList;
|
sum = mee.ArrayAlgorithms.GetSum(SumOfFifthNumbers);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -132,6 +126,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839
|
The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839
|
||||||
It took an average of 217.218 milliseconds to run this problem through 100 iterations
|
It took an average of 217.218 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem31.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem31.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-03-20
|
// Created: 10-03-20
|
||||||
//Modified: 10-03-20
|
//Modified: 07-05-21
|
||||||
//How many different ways can £2 be made using any number of coins?
|
//How many different ways can £2 be made using any number of coins?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -31,17 +31,13 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private int permutations; //The number of permutations that are found
|
private int permutations; //The number of permutations that are found
|
||||||
public int Permutations{
|
public int Permutations{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number of correct permutations of the coins");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return permutations;
|
return permutations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"There are {permutations} ways to make 2 pounds with the given denominations of coins";
|
return $"There are {permutations} ways to make 2 pounds with the given denominations of coins";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,6 +58,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start with 200p and remove the necessary coins with each loop
|
//Start with 200p and remove the necessary coins with each loop
|
||||||
for(int pound2 = desiredValue; pound2 >= 0;pound2 -= 200){
|
for(int pound2 = desiredValue; pound2 >= 0;pound2 -= 200){
|
||||||
for(int pound1 = pound2;pound1 >= 0;pound1 -= 100){
|
for(int pound1 = pound2;pound1 >= 0;pound1 -= 100){
|
||||||
@@ -79,6 +76,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -93,6 +91,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
There are 73682 ways to make 2 pounds with the given denominations of coins
|
There are 73682 ways to make 2 pounds with the given denominations of coins
|
||||||
It took an average of 117.971 microseconds to run this problem through 100 iterations
|
It took an average of 117.971 microseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem32.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem32.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-03-20
|
// Created: 10-03-20
|
||||||
//Modified: 10-03-20
|
//Modified: 07-05-21
|
||||||
//Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
//Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -78,17 +78,13 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Gets
|
//Gets
|
||||||
public long SumOfPandigitals{
|
public long SumOfPandigitals{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of the pandigitals");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sumOfPandigitals;
|
return sumOfPandigitals;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"There are {listOfProducts.Count} unique 1-9 pandigitals\nThe sum of the products of these pandigitals is {sumOfPandigitals}";
|
return $"There are {listOfProducts.Count} unique 1-9 pandigitals\nThe sum of the products of these pandigitals is {sumOfPandigitals}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,6 +106,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Create the multiplicand and start working your way up
|
//Create the multiplicand and start working your way up
|
||||||
for(int multiplicand = 1;multiplicand <= TOP_MULTIPLICAND;++multiplicand){
|
for(int multiplicand = 1;multiplicand <= TOP_MULTIPLICAND;++multiplicand){
|
||||||
//Run through all possible multipliers
|
//Run through all possible multipliers
|
||||||
@@ -133,6 +130,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
sumOfPandigitals += prod.Product;
|
sumOfPandigitals += prod.Product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -150,7 +148,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Make sure every number from 1-9 is contained exactly once
|
//Make sure every number from 1-9 is contained exactly once
|
||||||
for(int panNumber = 1;panNumber <= 9;++panNumber){
|
for(int panNumber = 1;panNumber <= 9;++panNumber){
|
||||||
//Make sure there is exactly one of this number contained in the string
|
//Make sure there is exactly one of this number contained in the string
|
||||||
if(mee.Algorithms.FindNumOccurrence(numberString, panNumber.ToString()[0]) != 1){
|
if(mee.StringAlgorithms.FindNumOccurrence(numberString, panNumber.ToString()[0]) != 1){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,6 +164,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
There are 7 unique 1-9 pandigitals
|
There are 7 unique 1-9 pandigitals
|
||||||
The sum of the products of these pandigitals is 45228
|
The sum of the products of these pandigitals is 45228
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem33.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem33.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 02-06-21
|
// Created: 02-06-21
|
||||||
//Modified: 02-07-21
|
//Modified: 07-05-21
|
||||||
/*
|
/*
|
||||||
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s
|
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s
|
||||||
We shall consider fractions like, 30/50 = 3/5, to be trivial examples
|
We shall consider fractions like, 30/50 = 3/5, to be trivial examples
|
||||||
@@ -46,28 +46,28 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The denominator of the product is {prodDenominator}";
|
return $"The denominator of the product is {prodDenominator}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<int> Numerators{
|
public List<int> Numerators{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("list of numerators");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return numerators;
|
return numerators;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<int> Denominators{
|
public List<int> Denominators{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("list of denominators");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return denominators;
|
return denominators;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public int ProdDenominator{
|
||||||
|
get{
|
||||||
|
SolvedCheck("result");
|
||||||
|
return prodDenominator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
//Constructor
|
//Constructor
|
||||||
@@ -87,6 +87,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Search every possible numerator/denominator pair
|
//Search every possible numerator/denominator pair
|
||||||
for(int denominator = MIN_DENOMINATOR;denominator <= MAX_DENOMINATOR;++denominator){
|
for(int denominator = MIN_DENOMINATOR;denominator <= MAX_DENOMINATOR;++denominator){
|
||||||
for(int numerator = MIN_NUMERATOR;(numerator < denominator) &&(numerator <= MAX_NUMERATOR);++numerator){
|
for(int numerator = MIN_NUMERATOR;(numerator < denominator) &&(numerator <= MAX_NUMERATOR);++numerator){
|
||||||
@@ -126,13 +127,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Get the product of the numbers
|
//Get the product of the numbers
|
||||||
int numProd = mee.Algorithms.GetProd(numerators);
|
int numProd = mee.ArrayAlgorithms.GetProd(numerators);
|
||||||
int denomProd = mee.Algorithms.GetProd(denominators);
|
int denomProd = mee.ArrayAlgorithms.GetProd(denominators);
|
||||||
//Get the gcd to reduce to lowest terms
|
//Get the gcd to reduce to lowest terms
|
||||||
int gcd = mee.Algorithms.GCD(numProd, denomProd);
|
int gcd = mee.NumberAlgorithms.GCD(numProd, denomProd);
|
||||||
//Save the denominator
|
//Save the denominator
|
||||||
prodDenominator = denomProd / gcd;
|
prodDenominator = denomProd / gcd;
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -148,6 +150,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The denominator of the product is 100
|
The denominator of the product is 100
|
||||||
It took an average of 221.559 microseconds to run this problem through 100 iterations
|
It took an average of 221.559 microseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem34.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem34.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-01-21
|
// Created: 06-01-21
|
||||||
//Modified: 06-01-21
|
//Modified: 07-05-21
|
||||||
//Find the sum of all numbers which are equal to the sum of the factorial of their digits
|
//Find the sum of all numbers which are equal to the sum of the factorial of their digits
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
@@ -37,27 +37,21 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all numbers that are the sum of their digit's factorials is {sum}";
|
return $"The sum of all numbers that are the sum of their digit's factorials is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returns the list of factorials from 0-9
|
//Returns the list of factorials from 0-9
|
||||||
public List<int> Factorials{
|
public List<int> Factorials{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("list of factorials");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return factorials;
|
return factorials;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returns the sum of all numbers equal to the sum of their digit's factorials
|
//Returns the sum of all numbers equal to the sum of their digit's factorials
|
||||||
public int Sum{
|
public int Sum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,9 +76,10 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Pre-compute the possible factorials from 0! to 9!
|
//Pre-compute the possible factorials from 0! to 9!
|
||||||
for(int cnt = 0;cnt <= 9;++cnt){
|
for(int cnt = 0;cnt <= 9;++cnt){
|
||||||
factorials[cnt] = mee.Algorithms.Factorial(cnt);
|
factorials[cnt] = mee.NumberAlgorithms.Factorial(cnt);
|
||||||
}
|
}
|
||||||
//Run through all possible numbers from 3-MAX_NUM and see if they equal the sum of their digit's factorials
|
//Run through all possible numbers from 3-MAX_NUM and see if they equal the sum of their digit's factorials
|
||||||
for(int cnt = 3;cnt < MAX_NUM;++cnt){
|
for(int cnt = 3;cnt < MAX_NUM;++cnt){
|
||||||
@@ -101,6 +96,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -119,6 +115,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all numbers that are the sum of their digit's factorials is 40730
|
The sum of all numbers that are the sum of their digit's factorials is 40730
|
||||||
It took an average of 73.852 milliseconds to run this problem through 100 iterations
|
It took an average of 73.852 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem35.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem35.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-05-21
|
// Created: 06-05-21
|
||||||
//Modified: 06-05-21
|
//Modified: 07-05-21
|
||||||
//How many circular primes are there below one million?
|
//How many circular primes are there below one million?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
@@ -37,36 +37,28 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The number of all circular prime numbers under {MAX_NUM} is {circularPrimes.Count}";
|
return $"The number of all circular prime numbers under {MAX_NUM} is {circularPrimes.Count}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returns the vector of primes < MAX_NUM
|
//Returns the vector of primes < MAX_NUM
|
||||||
public List<int> Primes{
|
public List<int> Primes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return primes;
|
return primes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returns the vector of circular primes < MAX_NUM
|
//Returns the vector of circular primes < MAX_NUM
|
||||||
public List<int> CircularPrimes{
|
public List<int> CircularPrimes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return circularPrimes;
|
return circularPrimes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returns the number of circular primes
|
//Returns the number of circular primes
|
||||||
public int NumCircularPrimes{
|
public int NumCircularPrimes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number of circular primes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return circularPrimes.Count;
|
return circularPrimes.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,8 +89,9 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Get all primes under 1,000,000
|
//Get all primes under 1,000,000
|
||||||
primes = mee.Algorithms.GetPrimes(MAX_NUM);
|
primes = mee.NumberAlgorithms.GetPrimes(MAX_NUM);
|
||||||
//Go through all primes, get all their rotations, and check if those numbers are also primes
|
//Go through all primes, get all their rotations, and check if those numbers are also primes
|
||||||
foreach(int prime in primes){
|
foreach(int prime in primes){
|
||||||
bool allRotationsPrime = true;
|
bool allRotationsPrime = true;
|
||||||
@@ -117,6 +110,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -132,6 +126,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The number of all circular prime numbers under 999999 is 55
|
The number of all circular prime numbers under 999999 is 55
|
||||||
It took an average of 1.946 seconds to run this problem through 100 iterations
|
It took an average of 1.946 seconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem36.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem36.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-29-21
|
// Created: 06-29-21
|
||||||
//Modified: 06-29-21
|
//Modified: 07-05-21
|
||||||
//Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
|
//Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
@@ -37,25 +37,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all base 10 and base 2 palindromic numbers < {MAX_NUM} is {sum}";
|
return $"The sum of all base 10 and base 2 palindromic numbers < {MAX_NUM} is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<int> Palindromes{
|
public List<int> Palindromes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("list of palindromes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return palindromes;
|
return palindromes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int SumOfPalindromes{
|
public int SumOfPalindromes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of all palindromes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,20 +71,22 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start with 1, check if it is a palindrome in base 10 and 2, and continue to MAX_NUM
|
//Start with 1, check if it is a palindrome in base 10 and 2, and continue to MAX_NUM
|
||||||
for(int num = 1;num < MAX_NUM;++num){
|
for(int num = 1;num < MAX_NUM;++num){
|
||||||
//Check if num is a palindrome
|
//Check if num is a palindrome
|
||||||
if(mee.Algorithms.IsPalindrome(num.ToString())){
|
if(mee.StringAlgorithms.IsPalindrome(num.ToString())){
|
||||||
//Convert num to base 2 and see if that is a palindrome
|
//Convert num to base 2 and see if that is a palindrome
|
||||||
string binNum = mee.Algorithms.ToBin(num);
|
string binNum = mee.NumberAlgorithms.ToBin(num);
|
||||||
if(mee.Algorithms.IsPalindrome(binNum)){
|
if(mee.StringAlgorithms.IsPalindrome(binNum)){
|
||||||
//Add num to the list of palindromes
|
//Add num to the list of palindromes
|
||||||
palindromes.Add(num);
|
palindromes.Add(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Get the sum of all palindromes in the list
|
//Get the sum of all palindromes in the list
|
||||||
sum = mee.Algorithms.GetSum(palindromes);
|
sum = mee.ArrayAlgorithms.GetSum(palindromes);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -107,6 +103,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all base 10 and base 2 palindromic numbers < 999999 is 872187
|
The sum of all base 10 and base 2 palindromic numbers < 999999 is 872187
|
||||||
It took an average of 140.447 milliseconds to run this problem through 100 iterations
|
It took an average of 140.447 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -37,25 +37,19 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The sum of all left and right truncatable primes is {sum}";
|
return $"The sum of all left and right truncatable primes is {sum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public List<long> TruncatablePrimes{
|
public List<long> TruncatablePrimes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("list of truncatable primes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return truncPrimes;
|
return truncPrimes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long SumOfTruncatablePrimes{
|
public long SumOfTruncatablePrimes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of truncatable primes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,8 +71,9 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Create the sieve and get the first prime number
|
//Create the sieve and get the first prime number
|
||||||
IEnumerator<long> sieve = mee.Algorithms.SieveOfEratosthenes().GetEnumerator();
|
IEnumerator<long> sieve = mee.NumberAlgorithms.SieveOfEratosthenes().GetEnumerator();
|
||||||
sieve.MoveNext();
|
sieve.MoveNext();
|
||||||
//Loop through the sieve until you get to the LAST_PRIME_BEFORE_CHECK
|
//Loop through the sieve until you get to the LAST_PRIME_BEFORE_CHECK
|
||||||
while(sieve.Current < LAST_PRIME_BEFORE_CHECK){
|
while(sieve.Current < LAST_PRIME_BEFORE_CHECK){
|
||||||
@@ -112,7 +107,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
string primeSubstring = primeString[truncLoc..];
|
string primeSubstring = primeString[truncLoc..];
|
||||||
//Convert the string to an int and see if the number is still prime
|
//Convert the string to an int and see if the number is still prime
|
||||||
long newPrime = long.Parse(primeSubstring);
|
long newPrime = long.Parse(primeSubstring);
|
||||||
if(!mee.Algorithms.IsPrime(newPrime)){
|
if(!mee.NumberAlgorithms.IsPrime(newPrime)){
|
||||||
isTruncPrime = false;
|
isTruncPrime = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -125,7 +120,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
string primeSubstring = primeString.Substring(0, primeString.Length - truncLoc);
|
string primeSubstring = primeString.Substring(0, primeString.Length - truncLoc);
|
||||||
//Conver the string to an int and see if the number is still prime
|
//Conver the string to an int and see if the number is still prime
|
||||||
long newPrime = long.Parse(primeSubstring);
|
long newPrime = long.Parse(primeSubstring);
|
||||||
if(!mee.Algorithms.IsPrime(newPrime)){
|
if(!mee.NumberAlgorithms.IsPrime(newPrime)){
|
||||||
isTruncPrime = false;
|
isTruncPrime = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -137,7 +132,8 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Get the sum of all elements in the trucPrimes vector
|
//Get the sum of all elements in the trucPrimes vector
|
||||||
sum = mee.Algorithms.GetSum(truncPrimes);
|
sum = mee.ArrayAlgorithms.GetSum(truncPrimes);
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem4.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem4.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//Find the largest palindrome made from the product of two 3-digit numbers
|
//Find the largest palindrome made from the product of two 3-digit numbers
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -36,17 +36,13 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private readonly List<int> palindromes; //Holds all numbers that turn out to be palindromes
|
private readonly List<int> palindromes; //Holds all numbers that turn out to be palindromes
|
||||||
public List<int> Palindromes{
|
public List<int> Palindromes{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("palindromes");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return palindromes;
|
return palindromes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int LargestPalindrom{
|
public int LargestPalindrom{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("largest palindrome");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return palindromes[^1];
|
return palindromes[^1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,9 +50,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The largest palindrome is {palindromes[^1]}";
|
return $"The largest palindrome is {palindromes[^1]}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +70,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start at the first 3-digit number and check every one up to the last 3-digit number
|
//Start at the first 3-digit number and check every one up to the last 3-digit number
|
||||||
for(int firstNum = START_NUM;firstNum <= END_NUM;++firstNum){
|
for(int firstNum = START_NUM;firstNum <= END_NUM;++firstNum){
|
||||||
//You can start at the location of the first number because everything before that has already been tested. (100 * 101 == 101 * 100)
|
//You can start at the location of the first number because everything before that has already been tested. (100 * 101 == 101 * 100)
|
||||||
@@ -98,6 +93,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Sort the palindromes so that the last one is the largest
|
//Sort the palindromes so that the last one is the largest
|
||||||
palindromes.Sort();
|
palindromes.Sort();
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -112,6 +108,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The largest palindrome is 906609
|
The largest palindrome is 906609
|
||||||
It took an average of 51.682 milliseconds to run this problem through 100 iterations
|
It took an average of 51.682 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem5.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem5.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -29,9 +29,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private int smallestNum; //The smallest number that is found
|
private int smallestNum; //The smallest number that is found
|
||||||
public int Number{
|
public int Number{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("number");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return smallestNum;
|
return smallestNum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,9 +37,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The smallest positive number evenly divisible by all numbers 1-20 is {smallestNum}";
|
return $"The smallest positive number evenly divisible by all numbers 1-20 is {smallestNum}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,6 +58,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Start at 20 because it must at least be divisible by 20. Increment by 2 because it must be an even number to be divisible by 2
|
//Start at 20 because it must at least be divisible by 20. Increment by 2 because it must be an even number to be divisible by 2
|
||||||
bool numFound = false; //A flag for finding the divisible number
|
bool numFound = false; //A flag for finding the divisible number
|
||||||
int currentNum = 20; //The number that it are currently checking against
|
int currentNum = 20; //The number that it are currently checking against
|
||||||
@@ -81,9 +78,10 @@ namespace ProjectEulerCS.Problems{
|
|||||||
currentNum += 2;
|
currentNum += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Save the current num,ber as the smallest
|
||||||
smallestNum = currentNum;
|
smallestNum = currentNum;
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -98,6 +96,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The smallest positive number evenly divisible by all numbers 1-20 is 232792560
|
The smallest positive number evenly divisible by all numbers 1-20 is 232792560
|
||||||
It took an average of 2.549 seconds to run this problem through 100 iterations
|
It took an average of 2.549 seconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem6.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem6.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -35,26 +35,20 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private long sumOfSquares; //Holds the sum of the squares of all the numbers
|
private long sumOfSquares; //Holds the sum of the squares of all the numbers
|
||||||
public long SumOfSquares{
|
public long SumOfSquares{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("sum of the squares");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return sumOfSquares;
|
return sumOfSquares;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private long squareOfSum; //Holds the square of the sum of all the numbers
|
private long squareOfSum; //Holds the square of the sum of all the numbers
|
||||||
public long SquareOfSum{
|
public long SquareOfSum{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("square of the sums");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return squareOfSum;
|
return squareOfSum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public long Difference{
|
public long Difference{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("difference between the two numbers");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return Math.Abs(sumOfSquares - squareOfSum);
|
return Math.Abs(sumOfSquares - squareOfSum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,9 +56,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is {Math.Abs(sumOfSquares - squareOfSum)}";
|
return $"The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is {Math.Abs(sumOfSquares - squareOfSum)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +77,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Run through all numbers and add them to the appropriate sums
|
//Run through all numbers and add them to the appropriate sums
|
||||||
for(int currentNum = START_NUM;currentNum <= END_NUM;++currentNum){
|
for(int currentNum = START_NUM;currentNum <= END_NUM;++currentNum){
|
||||||
sumOfSquares += (currentNum * currentNum); //Add the square to the correct variable
|
sumOfSquares += (currentNum * currentNum); //Add the square to the correct variable
|
||||||
@@ -93,6 +86,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Squaring the sum that needs it
|
//Squaring the sum that needs it
|
||||||
squareOfSum *= squareOfSum;
|
squareOfSum *= squareOfSum;
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -108,6 +102,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150
|
The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150
|
||||||
It took an average of 234.000 nanoseconds to run this problem through 100 iterations
|
It took an average of 234.000 nanoseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem67.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem67.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-26-20
|
// Created: 08-26-20
|
||||||
//Modified: 08-26-20
|
//Modified: 07-05-21
|
||||||
//Find the maximum total from top to bottom
|
//Find the maximum total from top to bottom
|
||||||
/*
|
/*
|
||||||
59
|
59
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -125,7 +125,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
|
||||||
@@ -240,6 +239,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The value of the longest path is 7273
|
The value of the longest path is 7273
|
||||||
It took an average of 216.985 milliseconds to run this problem through 100 iterations
|
It took an average of 216.985 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem7.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem7.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//What is the 10001th prime number?
|
//What is the 10001th prime number?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -34,9 +34,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private List<long> primes;
|
private List<long> primes;
|
||||||
public long Prime{
|
public long Prime{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("prime");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return primes[^1];
|
return primes[^1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,9 +42,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The {NUMBER_OF_PRIMES}th prime number is {primes[^1]}";
|
return $"The {NUMBER_OF_PRIMES}th prime number is {primes[^1]}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +63,10 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Setup the variables
|
//Setup the variables
|
||||||
primes = mee.Algorithms.GetNumPrimes(NUMBER_OF_PRIMES); //Holds the prime numbers
|
primes = mee.NumberAlgorithms.GetNumPrimes(NUMBER_OF_PRIMES); //Holds the prime numbers
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@@ -84,6 +82,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The 10001th prime number is 104743
|
The 10001th prime number is 104743
|
||||||
It took an average of 3.559 milliseconds to run this problem through 100 iterations
|
It took an average of 3.559 milliseconds to run this problem through 100 iterations
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem8.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem8.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
//Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
||||||
/*
|
/*
|
||||||
73167176531330624919225119674426574742355349194934
|
73167176531330624919225119674426574742355349194934
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -57,18 +57,14 @@ namespace ProjectEulerCS.Problems{
|
|||||||
private string maxNums; //Holds the string of the largest product
|
private string maxNums; //Holds the string of the largest product
|
||||||
public string LargestNums{
|
public string LargestNums{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("numbers that make the largest product");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return maxNums;
|
return maxNums;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private long maxProduct; //Holds the largest product of 13 numbers
|
private long maxProduct; //Holds the largest product of 13 numbers
|
||||||
public long LargestProduct{
|
public long LargestProduct{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("product of the numbers");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return maxProduct;
|
return maxProduct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,9 +72,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The greatest product is {maxProduct}\nThe numbers are {maxNums}";
|
return $"The greatest product is {maxProduct}\nThe numbers are {maxNums}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,6 +94,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Cycle through the string of numbers looking for the maximum product
|
//Cycle through the string of numbers looking for the maximum product
|
||||||
for(int cnt = 12;cnt < NUMBER.Length;++cnt){
|
for(int cnt = 12;cnt < NUMBER.Length;++cnt){
|
||||||
long currentProduct = Int64.Parse(NUMBER[cnt - 12].ToString()) * Int64.Parse(NUMBER[cnt - 11].ToString()) * Int64.Parse(NUMBER[cnt - 10].ToString()) * Int64.Parse(NUMBER[cnt - 9].ToString()) * Int64.Parse(NUMBER[cnt - 8].ToString()) * Int64.Parse(NUMBER[cnt - 7].ToString()) * Int64.Parse(NUMBER[cnt - 6].ToString()) * Int64.Parse(NUMBER[cnt - 5].ToString()) * Int64.Parse(NUMBER[cnt - 4].ToString()) * Int64.Parse(NUMBER[cnt - 3].ToString()) * Int64.Parse(NUMBER[cnt - 2].ToString()) * Int64.Parse(NUMBER[cnt - 1].ToString()) * Int64.Parse(NUMBER[cnt].ToString());
|
long currentProduct = Int64.Parse(NUMBER[cnt - 12].ToString()) * Int64.Parse(NUMBER[cnt - 11].ToString()) * Int64.Parse(NUMBER[cnt - 10].ToString()) * Int64.Parse(NUMBER[cnt - 9].ToString()) * Int64.Parse(NUMBER[cnt - 8].ToString()) * Int64.Parse(NUMBER[cnt - 7].ToString()) * Int64.Parse(NUMBER[cnt - 6].ToString()) * Int64.Parse(NUMBER[cnt - 5].ToString()) * Int64.Parse(NUMBER[cnt - 4].ToString()) * Int64.Parse(NUMBER[cnt - 3].ToString()) * Int64.Parse(NUMBER[cnt - 2].ToString()) * Int64.Parse(NUMBER[cnt - 1].ToString()) * Int64.Parse(NUMBER[cnt].ToString());
|
||||||
@@ -111,6 +106,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -126,6 +122,7 @@ namespace ProjectEulerCS.Problems{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The greatest product is 23514624000
|
The greatest product is 23514624000
|
||||||
The numbers are 5576689664895
|
The numbers are 5576689664895
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/ProjectEulerCS/src/Problems/Problem9.cs
|
//ProjectEuler/ProjectEulerCS/src/Problems/Problem9.cs
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 08-27-20
|
//Modified: 07-05-21
|
||||||
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
|
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2021 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -34,36 +34,28 @@ namespace ProjectEulerCS{
|
|||||||
private int a; //Holds the size of the first side
|
private int a; //Holds the size of the first side
|
||||||
public int SideA{
|
public int SideA{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("first side");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private int b; //Holds the size of the second side
|
private int b; //Holds the size of the second side
|
||||||
public int SideB{
|
public int SideB{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("second side");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private double c; //Holds the size of the hyp
|
private double c; //Holds the size of the hyp
|
||||||
public int SideC{
|
public int SideC{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("third side");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return (int)c;
|
return (int)c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private bool found; //A flag to determine if we have found the solution yet
|
private bool found; //A flag to determine if we have found the solution yet
|
||||||
public int Product{
|
public int Product{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("product of all three sides");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return a * b * (int)c;
|
return a * b * (int)c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,9 +63,7 @@ namespace ProjectEulerCS{
|
|||||||
//The results of the problem
|
//The results of the problem
|
||||||
public override string Result{
|
public override string Result{
|
||||||
get{
|
get{
|
||||||
if(!solved){
|
SolvedCheck("result");
|
||||||
throw new Unsolved();
|
|
||||||
}
|
|
||||||
return $"The Pythagorean triplet is {a} + {b} + {Math.Round(c)}\nThe numbers' product is {a * b * Math.Round(c)}";
|
return $"The Pythagorean triplet is {a} + {b} + {Math.Round(c)}\nThe numbers' product is {a * b * Math.Round(c)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,6 +86,7 @@ namespace ProjectEulerCS{
|
|||||||
//Start the timer
|
//Start the timer
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
|
||||||
//Loop through all possible a's
|
//Loop through all possible a's
|
||||||
while((a < GOAL_SUM) && !found){
|
while((a < GOAL_SUM) && !found){
|
||||||
b = a + 1; //b must be larget than a
|
b = a + 1; //b must be larget than a
|
||||||
@@ -116,6 +107,7 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
@@ -138,6 +130,7 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The Pythagorean triplet is 200 + 375 + 425
|
The Pythagorean triplet is 200 + 375 + 425
|
||||||
The numbers' product is 31875000
|
The numbers' product is 31875000
|
||||||
|
|||||||
Reference in New Issue
Block a user