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/Problem1.ts
|
||||
//Matthew Ellison
|
||||
// Created: 10-18-20
|
||||
//Modified: 10-26-20
|
||||
//Modified: 07-14-21
|
||||
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
||||
//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
|
||||
@@ -25,6 +25,7 @@
|
||||
import { Unsolved } from "../Unsolved";
|
||||
import {Problem} from "./Problem";
|
||||
|
||||
|
||||
export class Problem1 extends Problem{
|
||||
//Variables
|
||||
//Static variables
|
||||
@@ -48,9 +49,11 @@ export class Problem1 extends Problem{
|
||||
//Start the timer
|
||||
this.timer.start();
|
||||
|
||||
|
||||
//Get the sum of the progressions of 3 and 5 and remove the sum of progressions of the overlap
|
||||
this.fullSum = this.sumOfProgression(3) + this.sumOfProgression(5) - this.sumOfProgression(3 * 5);
|
||||
|
||||
|
||||
//Stop the timer
|
||||
this.timer.stop();
|
||||
|
||||
@@ -71,20 +74,17 @@ export class Problem1 extends Problem{
|
||||
//Gets
|
||||
//Returns the result of solving the problem
|
||||
public getResult(): string{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("result");
|
||||
return `The sum of all numbers < ${Problem1.TOP_NUM + 1} is ${this.fullSum}`;
|
||||
}
|
||||
//Returns the requested sum
|
||||
public getSum(): number{
|
||||
if(!this.solved){
|
||||
throw new Unsolved();
|
||||
}
|
||||
this.solvedCheck("sum");
|
||||
return this.fullSum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of all numbers < 1000 is 233168
|
||||
It took an average of 1.921 microseconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user