Updated to use new library layout

This commit is contained in:
2021-07-14 15:38:17 -04:00
parent ad2e948a42
commit b5c1df010f
39 changed files with 316 additions and 493 deletions

View File

@@ -1,7 +1,7 @@
//ProjectEulerTS/Problems/Problem37.ts
//Matthew Ellison
// Created: 07-01-21
//Modified: 07-01-21
//Modified: 07-14-21
//Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted).
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -21,10 +21,13 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { getSum, isPrime, sieveOfEratosthenes } from "../../../Typescript/typescriptClasses/Algorithms";
import { getSum } from "../../../Typescript/typescriptClasses/ArrayAlgorithms";
import { isPrime, sieveOfEratosthenes } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
import { Unsolved } from "../Unsolved";
import { Problem } from "./Problem";
export class Problem37 extends Problem{
//Variables
//Static variables
@@ -51,6 +54,7 @@ export class Problem37 extends Problem{
//Start the timer
this.timer.start();
//Create the sieve and get the first prime number
let sieve = sieveOfEratosthenes();
let tempPrime = sieve.next().value;
@@ -126,6 +130,7 @@ export class Problem37 extends Problem{
//Get the sum of all elements in the truncPrimes list
this.sum = getSum(this.truncPrimes);
//Stop the timer
this.timer.stop();
@@ -141,28 +146,22 @@ export class Problem37 extends Problem{
//Gets
//Returns a string with the solution to the problem
public getResult(): string{
//If the problem hasn't been solve dthrow an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `The sum of all left and right truncatable primes is ${this.sum}`;
}
//Returns the list of primes that can be truncated
public getTruncatablePrimes(): number[]{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of truncatable primes");
return this.truncPrimes;
}
//Returns the sum of all elements in truncPrimes
public getSumOfTruncatablePrimes(): number{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("sum of truncatable primes");
return this.sum;
}
}
/* Results:
The sum of all left and right truncatable primes is 748317
It took an average of 104.007 milliseconds to run this problem through 100 iterations