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/Problem12.ts
//Matthew Ellison
// Created: 03-26-21
//Modified: 03-26-21
//Modified: 07-14-21
//What is the value of the first triangle number to have over five hundred divisors?
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -23,8 +23,7 @@
import { Problem } from "./Problem";
import { Unsolved } from "../Unsolved";
import { getDivisors } from "../../../Typescript/typescriptClasses/Algorithms";
import { getDivisors } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
export class Problem12 extends Problem{
@@ -58,6 +57,7 @@ export class Problem12 extends Problem{
//Start the timer
this.timer.start();
//Loop until you find the appropriate number
while((!foundNumber) && (this.sum > 0)){
this.divisors = getDivisors(this.sum);
@@ -72,6 +72,7 @@ export class Problem12 extends Problem{
}
}
//Stop the timer
this.timer.stop();
@@ -88,46 +89,32 @@ export class Problem12 extends Problem{
//Gets
//Returns the result of solving the problem
public getResult(): string{
//If the problem hasn't bee solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `The triangular number ${this.sum} is the sum of all numbers >= ${this.counter - 1} and has ${this.divisors.length} divisors`;
}
//Returns the triangular number
public getTriangularNumber(): number{
//If the problem hasn't bee solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("triangular number");
return this.sum;
}
//Get the final number that was added to the triangular number
public getLastNumberAdded(): number{
//If the problem hasn't bee solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("last number added to get the triangular number");
return this.counter - 1;
}
//Returns the list of divisors of the requested number
public getDivisorsOfTriangularNumber(): number[]{
//If the problem hasn't bee solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("divisors of the triangular number");
return this.divisors;
}
//Returns the number of divisors of the requested number
public getNumberOfDivisors(): number{
//If the problem hasn't bee solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("number of divisors of the triangular number");
return this.divisors.length;
}
}
/* Results
The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors
It took an average of 301.951 milliseconds to run this problem through 100 iterations