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/Problem8.ts
|
||||
//Matthew Ellison
|
||||
// Created: 03-10-21
|
||||
//Modified: 03-10-21
|
||||
//Modified: 07-14-21
|
||||
//Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
||||
/*
|
||||
73167176531330624919225119674426574742355349194934
|
||||
@@ -45,7 +45,6 @@
|
||||
|
||||
|
||||
import { Problem } from "./Problem";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
|
||||
|
||||
export class Problem8 extends Problem{
|
||||
@@ -74,6 +73,7 @@ export class Problem8 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Cycle through the string of numbers looking for the maximum product
|
||||
for(let cnt: number = 12;cnt < Problem8.NUMBER.length;++cnt){
|
||||
let currentProduct: number = parseInt(Problem8.NUMBER.substring(cnt - 12, cnt - 11)) * parseInt(Problem8.NUMBER.substring(cnt - 11, cnt - 10)) * parseInt(Problem8.NUMBER.substring(cnt - 10, cnt - 9)) * parseInt(Problem8.NUMBER.substring(cnt - 9, cnt - 8)) * parseInt(Problem8.NUMBER.substring(cnt - 8, cnt - 7)) * parseInt(Problem8.NUMBER.substring(cnt - 7, cnt - 6)) * parseInt(Problem8.NUMBER.substring(cnt - 6, cnt - 5)) * parseInt(Problem8.NUMBER.substring(cnt - 5, cnt - 4)) * parseInt(Problem8.NUMBER.substring(cnt - 4, cnt - 3)) * parseInt(Problem8.NUMBER.substring(cnt - 3, cnt - 2)) * parseInt(Problem8.NUMBER.substring(cnt - 2, cnt - 1)) * parseInt(Problem8.NUMBER.substring(cnt - 1, cnt)) * parseInt(Problem8.NUMBER.substring(cnt, cnt + 1));
|
||||
@@ -85,6 +85,7 @@ export class Problem8 extends Problem{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -98,29 +99,22 @@ export class Problem8 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 product is ${this.maxProduct}\nThe numbers are ${this.maxNums}`;
|
||||
}
|
||||
//Returns the string of numbers that produces the largest product
|
||||
public getLargestNums(): string{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("numbers that make the largest product");
|
||||
return this.maxNums;
|
||||
}
|
||||
//Returns the requested product
|
||||
public getLargestProduct(): number{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("product of the numbers");
|
||||
return this.maxProduct;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The greatest product is 23514624000
|
||||
The numbers are 5576689664895
|
||||
|
||||
Reference in New Issue
Block a user