mirror of
https://bitbucket.org/Mattrixwv/projecteulerts.git
synced 2025-12-06 17:43:59 -05:00
Updated to use new library layout
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user