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/Problem14.ts
|
||||
//Matthew Ellison
|
||||
// Created: 03-26-21
|
||||
//Modified: 03-26-21
|
||||
//Modified: 07-14-21
|
||||
/*
|
||||
The following iterative sequence is defined for the set of positive integers:
|
||||
n → n/2 (n is even)
|
||||
@@ -27,7 +27,6 @@ Which starting number, under one million, produces the longest chain?
|
||||
*/
|
||||
|
||||
|
||||
import { Unsolved } from "../Unsolved";
|
||||
import { Problem } from "./Problem";
|
||||
|
||||
|
||||
@@ -57,6 +56,7 @@ export class Problem14 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Loop through all numbers <= MAX_NUM and check them against the series
|
||||
for(let currentNum = 1;currentNum <= Problem14.MAX_NUM;++currentNum){
|
||||
let currentLength: number = this.checkSeries(currentNum);
|
||||
@@ -67,6 +67,7 @@ export class Problem14 extends Problem{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -99,30 +100,22 @@ export class Problem14 extends Problem{
|
||||
}
|
||||
//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 number ${this.maxNum} produced a chain of ${this.maxLength} steps`;
|
||||
}
|
||||
//Returns the length of the requested chain
|
||||
public getLength(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("length of the longest chain");
|
||||
return this.maxLength;
|
||||
}
|
||||
//Returns the starting number of the requested chain
|
||||
public getStartingNumber(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("starting number of the longest chain");
|
||||
return this.maxNum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The number 837799 produced a chain of 525 steps
|
||||
It took an average of 1.178 seconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user