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/Problem24.ts
//Matthew Ellison
// Created: 04-08-21
//Modified: 04-08-21
//Modified: 07-14-21
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
/*
@@ -22,8 +22,7 @@
*/
import { getPermutations } from "../../../Typescript/typescriptClasses/Algorithms";
import { Unsolved } from "../Unsolved";
import { getPermutations } from "../../../Typescript/typescriptClasses/StringAlgorithms";
import { Problem } from "./Problem";
@@ -52,9 +51,11 @@ export class Problem24 extends Problem{
//Start the timer
this.timer.start();
//Get all the permutations of the string
this.permutations = getPermutations(Problem24.nums);
//Stop the timer
this.timer.stop();
@@ -69,28 +70,22 @@ export class Problem24 extends Problem{
//Gets
//Returns the result of solving the problem
public getResult(): string{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `The 1 millionth permutation is ${this.permutations[Problem24.NEEDED_PERM - 1]}`;
}
//Returns an array with all of the permutations
public getPermutationsList(): string[]{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("permutations");
return this.permutations;
}
//Returns the requested permutation
public getPermutation(){
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("1,000,000th permutation");
return this.permutations[Problem24.NEEDED_PERM - 1];
}
}
/* Results:
The 1 millionth permutation is 2783915460
It took an average of 1.946 seconds to run this problem through 100 iterations