Updated to use new library layout

This commit is contained in:
2021-07-14 15:38:17 -04:00
parent ad2e948a42
commit b5c1df010f
39 changed files with 316 additions and 493 deletions

View File

@@ -1,11 +1,11 @@
//ProjectEulerTS/Problems/Problem2.ts
//Matthew Ellison
// Created: 10-19-20
//Modified: 10-19-20
//Modified: 07-14-21
//The sum of the even Fibonacci numbers less than 4,000,000
//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,8 +23,7 @@
import { Problem } from "./Problem";
import { getAllFib } from "../../../Typescript/typescriptClasses/Algorithms";
import { Unsolved } from "../Unsolved";
import { getAllFib } from "../../../Typescript/typescriptClasses/NumberAlgorithms";
export class Problem2 extends Problem{
@@ -51,6 +50,7 @@ export class Problem2 extends Problem{
//Start the timer
this.timer.start();
//Get a list of all fibonacci numbers <= TOP_NUM
let fibNums = getAllFib(Problem2.TOP_NUM);
//Setp through every element in the list checking ifit is even
@@ -61,6 +61,7 @@ export class Problem2 extends Problem{
}
});
//Stop the timer
this.timer.stop();
@@ -75,20 +76,17 @@ export class Problem2 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 even fibonacci numbers <= ${Problem2.TOP_NUM} 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 even fibonacci numbers <= 3999999 is 4613732
It took an average of 6.330 microseconds to run this problem through 100 iterations