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,11 +1,11 @@
#ProjectEuler/Python/Problem4.py
#Matthew Ellison
# Created: 01-28-19
#Modified: 10-30-20
#Modified: 07-24-21
#Find the largest palindrome made from the product of two 3-digit numbers
#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
@@ -23,7 +23,6 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
class Problem4(Problem):
@@ -33,13 +32,13 @@ class Problem4(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("Find the largest palindrome made from the product of two 3-digit numbers")
self.palindromes = [] #Holds all of the palindromes
#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
@@ -47,6 +46,7 @@ class Problem4(Problem):
#Start the timer
self.timer.start()
#Loop through every number from __lowestNum to __highestNum twice and multiply every number together
for firstNum in range(self.__lowestNum, self.__highestNum + 1):
for secondNum in range(firstNum, self.__highestNum + 1): #You can start at num1 because 100 * 101 == 101 * 100
@@ -61,6 +61,7 @@ class Problem4(Problem):
#Sort the palindromes so that the last element is the largest
self.palindromes.sort()
#Stop the timer
self.timer.stop()
@@ -68,28 +69,22 @@ class Problem4(Problem):
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.palindromes.clear()
#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 largest palindrome made from the product of two 3-digit numbers is {self.palindromes[len(self.palindromes) - 1]}"
#Returns the list of all palindromes
def getPalindromes(self) -> list:
#If the problem hasn't been solved throw an exceptions
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the list of palindromes")
self.solvedCheck("palindromes")
return self.palindromes
#Returns the largest palindrome
def getLargestPalindrome(self) -> int:
#If the problem hasn't been solved throw an exceptions
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the largest palindrome")
self.solvedCheck("largest palindrome")
return self.palindromes[len(self.palindromes) - 1]