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/Problem33.ts
//Matthew Ellison
// Created: 05-28-21
//Modified: 05-28-21
//Modified: 07-14-21
/*
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s
We shall consider fractions like, 30/50 = 3/5, to be trivial examples
@@ -27,8 +27,8 @@ If the product of these four fractions is given in its lowest common terms, find
*/
import { gcd, getProd } from "../../../Typescript/typescriptClasses/Algorithms";
import { Unsolved } from "../Unsolved";
import { getProd } from "../../../Typescript/typescriptClasses/ArrayAlgorithms";
import { gcd } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
import { Problem } from "./Problem";
@@ -63,6 +63,7 @@ export class Problem33 extends Problem{
//Start the timer
this.timer.start();
//Search every possible numerator/denominator pair
for(let denominator = Problem33.MIN_DENOMINATOR;denominator <= Problem33.MAX_DENOMINATOR;++denominator){
for(let numerator = Problem33.MIN_NUMERATOR;(numerator < denominator) && (numerator <= Problem33.MAX_NUMERATOR);++numerator){
@@ -109,6 +110,7 @@ export class Problem33 extends Problem{
//Save the denominator
this.prodDenominator = denomProd / curGcd;
//Stop the timer
this.timer.stop();
@@ -124,37 +126,27 @@ export class Problem33 extends Problem{
//Gets
//Returns the reult of solving the problem
public getResult(): string{
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("result");
return `The denominator of the product is ${this.prodDenominator}`;
}
//Returns the list of numerators
public getNumerators(): number[]{
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of numerators");
return this.numerators;
}
//Returns the list of denominators
public getDenominators(): number[]{
//If the porblem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("list of denominators");
return this.denominators;
}
//Returns the answer to the question
public getProdDenominator(){
//If the problem hasn't been solved throw an exception
if(!this.solved){
throw new Unsolved();
}
this.solvedCheck("denominator");
return this.prodDenominator;
}
}
/* Results:
The denominator of the product is 100
It took an average of 508.730 microseconds to run this problem through 100 iterations