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/Problem26.ts
|
||||
//Matthew Ellison
|
||||
// Created: 05-24-21
|
||||
//Modified: 05-24-21
|
||||
//Modified: 07-14-21
|
||||
//Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
|
||||
/*
|
||||
@@ -22,8 +22,7 @@
|
||||
*/
|
||||
|
||||
|
||||
import { isPrime } from "../../../Typescript/typescriptClasses/Algorithms";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
import { isPrime } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
|
||||
import { Problem } from "./Problem";
|
||||
|
||||
|
||||
@@ -56,6 +55,7 @@ export class Problem27 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Start with the lowest possible A and check all possibilities after that
|
||||
for(let a: number = -Problem27.LARGEST_POSSIBLE_A; a <= Problem27.LARGEST_POSSIBLE_A;++a){
|
||||
//Start witht he lowest possible B and check all possibilities after that
|
||||
@@ -78,6 +78,7 @@ export class Problem27 extends Problem{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -94,45 +95,32 @@ export class Problem27 extends Problem{
|
||||
//Gets
|
||||
//Returns the result of solving the problem
|
||||
public getResult(): string{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("result");
|
||||
return `The greatest number of primes found is ${this.topN}\nIt was found with A = ${this.topA}, B = ${this.topB}\nThe product of A and B is ${this.getProduct()}`;
|
||||
}
|
||||
//Returns the top A that was generated
|
||||
public getTopA(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("largest A");
|
||||
return this.topA;
|
||||
}
|
||||
//Returns the top B that was generated
|
||||
public getTopB(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("largest B");
|
||||
return this.topB;
|
||||
}
|
||||
//Returns the top N that was generated
|
||||
public getTopN(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("largest N");
|
||||
return this.topN;
|
||||
}
|
||||
//Returns the product of A and B for the answer
|
||||
public getProduct(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("product of A and B");
|
||||
return this.topA * this.topB;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The greatest number of primes found is 70
|
||||
It was found with A = -61, B = 971
|
||||
|
||||
Reference in New Issue
Block a user