Updated to use new library layout

This commit is contained in:
2021-07-24 16:13:05 -04:00
parent d18b3fa9f6
commit 84555edd31
39 changed files with 515 additions and 709 deletions

View File

@@ -1,7 +1,7 @@
#ProjectEuler/Python/Problem14.py
#Matthew Ellison
# Created: 01-31-19
#Modified: 10-30-20
#Modified: 07-24-21
"""
The following iterative sequence is defined for the set of positive integers:
n → n/2 (n is even)
@@ -10,7 +10,7 @@ Which starting number, under one million, produces the longest chain?
"""
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
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
@@ -28,7 +28,6 @@ Which starting number, under one million, produces the longest chain?
from Problems.Problem import Problem
from Unsolved import Unsolved
class Problem14(Problem):
@@ -37,14 +36,14 @@ class Problem14(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("Which starting number, under one million, produces the longest chain using the itterative sequence?")
self.maxLength = 0
self.maxNum = 0
#Operational functions
#Solve the problem
def solve(self):
def solve(self) -> None:
#If the problem has already been solved do nothing and end the function
if(self.solved):
return
@@ -52,6 +51,7 @@ class Problem14(Problem):
#Start the timer
self.timer.start()
#Loop through all number <= topNum and check them against the series
for currentNum in range(1, self.__topNum + 1):
currentLength = self.checkSeries(currentNum)
@@ -60,6 +60,7 @@ class Problem14(Problem):
self.maxLength = currentLength
self.maxNum = currentNum
#Stop the timer
self.timer.stop()
@@ -81,29 +82,23 @@ class Problem14(Problem):
return length
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.maxLength = 0
self.maxNum = 0
#Gets
#Returns the result of solving the problem
def getResult(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before you can see the result")
def getResult(self) -> str:
self.solvedCheck("result")
return f"The number {self.maxNum} produced a chain of {self.maxLength} steps"
#Returns the length of the requested chain
def getLength(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the length of the requested chain")
def getLength(self) -> int:
self.solvedCheck("length of the longest chain")
return self.maxLength
#Returns the starting number of the requested chain
def getStartingNumber(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the number that started the series")
def getStartingNumber(self) -> int:
self.solvedCheck("starting number of the longest chain")
return self.maxNum