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/Problem34.ts
//Matthew Ellison
// Created: 06-01-21
//Modified: 06-01-21
//Modified: 07-14-21
//Find the sum of all numbers which are equal to the sum of the factorial of their digits
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -22,8 +22,7 @@
*/
import { factorial } from "../../../Typescript/typescriptClasses/Algorithms";
import { Unsolved } from "../Unsolved";
import { factorial } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
import { Problem } from "./Problem";
@@ -56,6 +55,7 @@ export class Problem34 extends Problem{
//Start the timer
this.timer.start();
//Pre-compute the possible factorials form 0! to 9!
for(let cnt = 0;cnt <= 9;++cnt){
this.factorials[cnt] = factorial(cnt);
@@ -75,6 +75,7 @@ export class Problem34 extends Problem{
}
}
//Stop the timer
this.timer.stop();
@@ -93,30 +94,22 @@ export class Problem34 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 numbers that are the sum of their digit's factorials is ${this.sum}`;
}
//Returns the list of factorials from 0-9
public getFactorials(): number[]{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of factorials");
return this.factorials;
}
//Returns the sum of all numbers equal to the sum of their digit's factorials
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 numbers that are the sum of their digit's factorials is 40730
It took an average of 87.615 milliseconds to run this problem through 100 iterations