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/Problem20.ts
//Matthew Ellison
// Created: 04-07-21
//Modified: 04-07-21
//Modified: 07-14-21
//What is the sum of the digits of 100!?
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -22,7 +22,6 @@
*/
import { Unsolved } from "../Unsolved";
import { Problem } from "./Problem";
@@ -52,6 +51,7 @@ export class Problem20 extends Problem{
//Start the timer
this.timer.start();
//Run through every number from 1 to 100 and multiply it by the current num to generate 100!
for(let cnt = Problem20.TOP_NUM;cnt > 1;--cnt){
this.num *= BigInt(cnt);
@@ -65,6 +65,7 @@ export class Problem20 extends Problem{
this.sum += parseInt(digit);
}
//Stop the timer
this.timer.stop();
@@ -80,37 +81,27 @@ export class Problem20 extends Problem{
//Gets
//Returns the result of solving the problem
public getResult(): string{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `${Problem20.TOP_NUM}! = ${this.num}\nThe sum of the digits is: ${this.sum}`;
}
//Returns the number 100!
public getNumber(): bigint{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("number");
return this.num;
}
//Returns the number 100! in a string
public getNumberString(): string{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("number as a string");
return this.num.toString();
}
//Returns the sum of the digits of 100!
public getSum(): number{
//If the porblem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("sum of the digits");
return this.sum;
}
}
/* Results:
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
The sum of the digits is: 648