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/Problem16.ts
//Matthew Ellison
// Created: 03-29-21
//Modified: 03-29-21
//Modified: 07-14-21
//What is the sum of the digits of the number 2^1000?
//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";
@@ -53,6 +52,7 @@ export class Problem16 extends Problem{
//Start the timer
this.timer.start();
//Get the number
this.num = Problem16.NUM_TO_POWER ** Problem16.POWER;
@@ -64,6 +64,7 @@ export class Problem16 extends Problem{
this.sumOfElements += parseInt(numString.charAt(cnt));
}
//Stop the timer
this.timer.stop();
@@ -79,27 +80,22 @@ export class Problem16 extends Problem{
//Gets
//Returns the result of solving the problem
public getResult(): string{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `${Problem16.NUM_TO_POWER}^${Problem16.POWER} = ${this.num}\nThe sum of the elements is ${this.sumOfElements}`;
}
//Returns the number that was calculated
public getNumber(): bigint{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("number");
return this.num;
}
//Returns the sum o the digits of the number
public getSum(): number{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("sum");
return this.sumOfElements;
}
}
/* Results:
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
The sum of the elements is 1366