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/Problem35.ts
//Matthew Ellison
// Created: 06-06-21
//Modified: 06-06-21
//Modified: 07-14-21
//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/typescriptClasses
/*
@@ -22,8 +22,7 @@
*/
import { getPrimes } from "../../../Typescript/typescriptClasses/Algorithms";
import { Unsolved } from "../Unsolved";
import { getPrimes } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
import { Problem } from "./Problem";
@@ -62,6 +61,7 @@ export class Problem35 extends Problem{
//Start the timer
this.timer.start();
//Get all primes under 1,000,000
this.primes = getPrimes(Problem35.MAX_NUM);
//Go through all primes, get all their rotations, and check if htose numbers are also primes
@@ -84,6 +84,7 @@ export class Problem35 extends Problem{
}
}
//Stop the timer
this.timer.stop();
@@ -99,38 +100,27 @@ export class Problem35 extends Problem{
//Gets
//Returns a string with the solution to the problem
public getResult(): string{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `The number of all circular prime numbers under ${Problem35.MAX_NUM} is ${this.circularPrimes.length}`;
}
//Returns the array of primes < MAX_NUM
public getPrimes(): number[]{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of primes");
return this.primes;
}
//Returns the array of circular primes < MAX_NUM
public getCircularPrimes(): number[]{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of circular primes");
return this.circularPrimes;
}
//Returns the number of circular primes < MAX_NUM
public getNumCircularPrimes(): number{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("number oc circular primes");
return this.circularPrimes.length;
}
}
/* Results:
The number of all circular prime numbers under 999999 is 55
It took an average of 7.204 seconds to run this problem through 100 iterations