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,11 +1,11 @@
|
||||
//ProjectEulerTS/Problems/Problem5.ts
|
||||
//Matthew Ellison
|
||||
// Created: 10-26-20
|
||||
//Modified: 10-26-20
|
||||
//Modified: 07-14-21
|
||||
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/typescriptClasses
|
||||
/*
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
import { Problem } from "./Problem";
|
||||
import { Unsolved } from "../Unsolved";
|
||||
|
||||
|
||||
export class Problem5 extends Problem{
|
||||
@@ -48,6 +47,7 @@ export class Problem5 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Start at 20 because it must at least be divisible by 20. Increment by 2 because it must be an even number to be divisible by 2
|
||||
let numFound: boolean = false; //A flag for finding the divisible number
|
||||
let currentNum: number = 20; //The number that it is currently checking against
|
||||
@@ -67,9 +67,10 @@ export class Problem5 extends Problem{
|
||||
currentNum += 2;
|
||||
}
|
||||
}
|
||||
|
||||
//Save the current number as the smallest
|
||||
this.smallestNum = currentNum
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -84,20 +85,17 @@ export class Problem5 extends Problem{
|
||||
//Gets
|
||||
//Returns the result of solving the problem
|
||||
public getResult(): string{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("result");
|
||||
return `The smallest positive number evenly divisible by all number 1-20 is ${this.smallestNum}`;
|
||||
}
|
||||
//Returns the requested number
|
||||
public getNumber(): number{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("number");
|
||||
return this.smallestNum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The smallest positive number evenly divisible by all number 1-20 is 232792560
|
||||
It took an average of 892.378 milliseconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user