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/Problem7.ts
//Matthew Ellison
// Created: 03-10-21
//Modified: 03-10-21
//Modified: 07-14-21
//What is the 10001th prime number?
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -23,8 +23,7 @@
import { Problem } from "./Problem";
import { Unsolved } from "../Unsolved";
import { getNumPrimes } from "../../../Typescript/typescriptClasses/Algorithms";
import { getNumPrimes } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
export class Problem7 extends Problem{
@@ -50,9 +49,11 @@ export class Problem7 extends Problem{
//Start the timer
this.timer.start();
//Setup the variables
this.primes = getNumPrimes(Problem7.NUMBER_OF_PRIMES); //Holds the prime numbers
//Stop the timer
this.timer.stop();
@@ -67,21 +68,17 @@ export class Problem7 extends Problem{
//Gets
//Returns the result of solving the problem
public getResult(): string{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `The ${Problem7.NUMBER_OF_PRIMES}th prime number is ${this.getPrime()}`;
}
//Returns the requested prime number
public getPrime(): number{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("prime");
return this.primes[this.primes.length - 1];
}
}
/* Results:
The 10001th prime number is 104743
It took an average of 3.534 milliseconds to run this problem through 100 iterations