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,11 +1,11 @@
|
||||
//ProjectEulerTS/Problems/Problem4.ts
|
||||
//Matthew Ellison
|
||||
// Created: 10-24-20
|
||||
//Modified: 10-24-20
|
||||
//Modified: 07-14-21
|
||||
//Find the largest palindrome made from the product of two 3-digit numbers
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
|
||||
/*
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
import { Problem } from "./Problem";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
|
||||
|
||||
export class Problem4 extends Problem{
|
||||
@@ -49,6 +48,7 @@ export class Problem4 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Start at the first 3-digit number and check every one up to the last 3-digit number
|
||||
for(let firstNum: number = Problem4.START_NUM;firstNum <= Problem4.END_NUM;++firstNum){
|
||||
//You can start at the location of the first number because everything before that has already been tested. (100 * 101 == 101 * 100)
|
||||
@@ -71,6 +71,7 @@ export class Problem4 extends Problem{
|
||||
//Sort the palindromes so that the last one is the largest
|
||||
this.palindromes = this.palindromes.sort((n1, n2) => n1 - n2);
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -86,27 +87,22 @@ export class Problem4 extends Problem{
|
||||
//Gets
|
||||
//Returns the result of solving the problem
|
||||
public getResult(): string{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("result");
|
||||
return `The largest palindrome is ${this.palindromes[this.palindromes.length - 1]}`;
|
||||
}
|
||||
//Returns the list of all palindromes
|
||||
public getPalindromes(): number[]{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("palindromes");
|
||||
return this.palindromes;
|
||||
}
|
||||
//Returns the largest palindrome
|
||||
public getLargestPalindrome(): number{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("largest palindrome");
|
||||
return this.palindromes[this.palindromes.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The largest palindrome is 906609
|
||||
It took an average of 121.130 milliseconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user