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/Problem30.ts
|
||||
//Matthew Ellison
|
||||
// Created: 05-28-21
|
||||
//Modified: 05-28-21
|
||||
//Modified: 07-14-21
|
||||
//Find the sum of all the numbers that can be written as the sum of the fifth powers 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 { getSum } from "../../../Typescript/typescriptClasses/Algorithms";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
import { getSum } from "../../../Typescript/typescriptClasses/ArrayAlgorithms";
|
||||
import { Problem } from "./Problem";
|
||||
|
||||
|
||||
@@ -66,6 +65,7 @@ export class Problem30 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Start with the lowest number and increment until you reach the largest number
|
||||
for(let currentNum = Problem30.BOTTOM_NUM;currentNum <= Problem30.TOP_NUM;++currentNum){
|
||||
//Get the digits of the number
|
||||
@@ -85,6 +85,7 @@ export class Problem30 extends Problem{
|
||||
//Get the sum of the numbers
|
||||
this.sum = getSum(this.sumOfFifthNumbers);
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -99,9 +100,7 @@ export class Problem30 extends Problem{
|
||||
//Gets
|
||||
//Returns the result of solving the problem
|
||||
public getResult(): string{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("result");
|
||||
return `This sum of all the numbers that can be written as the sum of the fifth powers of their digits is ${this.sum}`;
|
||||
}
|
||||
//This returns the top number to be checked
|
||||
@@ -110,22 +109,17 @@ export class Problem30 extends Problem{
|
||||
}
|
||||
//This returns a copy of the vector holding all the numbers that are the sum of the fifth power of their digits
|
||||
public getListOfSumOfFifths(): number[]{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("list of all numbers that are the sum of the 5th power of their digits");
|
||||
return this.sumOfFifthNumbers;
|
||||
}
|
||||
//This returns the sum of all entries in sumOfFifthNumbers
|
||||
public getSumOfList(): number{
|
||||
//If the problem hasn't been solved throw an eception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("sum of all numbers that are the sum of the 5th power of their digits");
|
||||
return this.sum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
This sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839
|
||||
It took an average of 180.976 milliseconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user