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/Problem9.ts
|
||||
//Matthew Ellison
|
||||
// Created: 03-24-21
|
||||
//Modified: 03-24-21
|
||||
//Modified: 07-14-21
|
||||
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
|
||||
/*
|
||||
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
|
||||
|
||||
import { Problem } from "./Problem";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
import { Problem } from "./Problem";
|
||||
|
||||
|
||||
export class Problem9 extends Problem{
|
||||
@@ -56,6 +56,7 @@ export class Problem9 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Loop through all possible a's
|
||||
while((this.a < Problem9.GOAL_SUM) && (!this.found)){
|
||||
this.b = this.a + 1; //b must be larger than a
|
||||
@@ -76,6 +77,7 @@ export class Problem9 extends Problem{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -98,46 +100,32 @@ export class Problem9 extends Problem{
|
||||
//Gets
|
||||
//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 Pythagorean triplet is ${this.a} + ${this.b} + ${this.c}\nThe numbers' product is ${this.getProduct()}`;
|
||||
}
|
||||
//Returns the length of the first side
|
||||
public getSideA(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("first side");
|
||||
return this.a;
|
||||
}
|
||||
//Returns the length of the second side
|
||||
public getSideB(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("second side");
|
||||
return this.b;
|
||||
}
|
||||
//Returns the length of the hyp
|
||||
public getSideC(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("third side");
|
||||
return this.c;
|
||||
}
|
||||
//Returns the product of the 3 sides
|
||||
public getProduct(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("product of all three sides");
|
||||
return this.a * this.b * this.c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The Pythagorean triplet is 200 + 375 + 425
|
||||
The numbers' product is 31875000
|
||||
|
||||
Reference in New Issue
Block a user