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/Problem13.ts
|
||||
//Matthew Ellison
|
||||
// Created: 03-26-21
|
||||
//Modified: 03-26-21
|
||||
//Modified: 07-14-21
|
||||
//Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
||||
/*
|
||||
37107287533902102798797998220837590246510135740250
|
||||
@@ -125,8 +125,7 @@
|
||||
|
||||
|
||||
import { Problem } from "./Problem";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
import { getSumBig } from "../../../Typescript/typescriptClasses/Algorithms";
|
||||
import { getSumBig } from "../../../Typescript/typescriptClasses/ArrayAlgorithms";
|
||||
|
||||
|
||||
export class Problem13 extends Problem{
|
||||
@@ -252,9 +251,11 @@ export class Problem13 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Get the sum of all the numbers
|
||||
this.sum = getSumBig(Problem13.nums);
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -269,30 +270,22 @@ export class Problem13 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 ${Problem13.nums.length} numbers is ${this.sum}\nThe first 10 digits of the sum of the numbers is ${this.sum.toString().substr(0, 10)}`;
|
||||
}
|
||||
//Returns the list of 50-digit numbers
|
||||
public getNumbers(): bigint[]{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("numbers");
|
||||
return Problem13.nums;
|
||||
}
|
||||
//Returns the sum of the 50-digit numbers
|
||||
public getSum(): bigint{
|
||||
//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 100 numbers is 5537376230390876637302048746832985971773659831892672
|
||||
The first 10 digits of the sum of the numbers is 5537376230
|
||||
|
||||
Reference in New Issue
Block a user