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/Problem36.ts
//Matthew Ellison
// Created: 06-29-21
//Modified: 06-29-21
//Modified: 07-14-21
//Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -22,8 +22,9 @@
*/
import { getSum, isPalindrome, toBin } from "../../../Typescript/typescriptClasses/Algorithms";
import { Unsolved } from "../Unsolved";
import { getSum } from "../../../Typescript/typescriptClasses/ArrayAlgorithms";
import { toBin } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
import { isPalindrome } from "../../../Typescript/typescriptClasses/StringAlgorithms";
import { Problem } from "./Problem";
@@ -53,6 +54,7 @@ export class Problem36 extends Problem{
//Start the timer
this.timer.start();
//Start with 1, check if it is a palindrome in base 10 and 2, and continue to MAX_NUM
for(let num = 1;num < Problem36.MAX_NUM;++num){
//Check if num is a palindrome
@@ -68,6 +70,7 @@ export class Problem36 extends Problem{
//Get the sum of all palindromes in the list
this.sum = getSum(this.palindromes);
//Stop the timer
this.timer.stop();
@@ -83,30 +86,22 @@ export class Problem36 extends Problem{
//Gets
//Returns a string with the solution to 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 base 10 and base 2 palindromic numbers < ${Problem36.MAX_NUM} is ${this.sum}`;
}
//Return the array of palindromes < MAX_NUM
public getPalindromes(){
//If the porblem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of palindromes");
return this.palindromes;
}
//Returns the sum of all elements in the array of palindromes
public getSumOfPalindromes(){
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("sum of all palindromes");
return this.sum;
}
}
/* Results:
The sum of all base 10 and base 2 palindromic numbers < 999999 is 872187
It took an average of 297.957 milliseconds to run this problem through 100 iterations