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/Problem10.ts
//Matthew Ellison
// Created: 03-24-21
//Modified: 03-24-21
//Modified: 07-14-21
//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/typescriptClasses
/*
@@ -23,8 +23,8 @@
import { Problem } from "./Problem";
import { Unsolved } from "../Unsolved";
import { getPrimes, getSum } from "../../../Typescript/typescriptClasses/Algorithms";
import { getSum } from "../../../Typescript/typescriptClasses/ArrayAlgorithms";
import { getPrimes } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
export class Problem10 extends Problem{
@@ -51,9 +51,11 @@ export class Problem10 extends Problem{
//Start the timer
this.timer.start();
//Get the sum of all prime numbers < GOAL_NUMBER
this.sum = getSum(getPrimes(Problem10.GOAL_NUMBER));
//Stop the timer
this.timer.stop();
@@ -68,22 +70,17 @@ export class Problem10 extends Problem{
//Gets
//Returns the result of solving 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 sum of all the primes < ${Problem10.GOAL_NUMBER + 1} is ${this.sum}`;
}
//Returns the sum that was requested
public getSum(): number{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("sum");
return this.sum;
}
}
/* Results:
The sum of all the primes < 2000000 is 142913828922
It took an average of 170.840 milliseconds to run this problem through 100 iterations