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/Problem29.py
#Matthew Ellison
# Created: 10-10-19
#Modified: 10-30-20
#Modified: 07-24-21
#How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
#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 Problem29(Problem):
@@ -35,13 +34,13 @@ class Problem29(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?")
self.unique = []
#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
@@ -49,6 +48,7 @@ class Problem29(Problem):
#Start the timer
self.timer.start()
#Start with the first A and move towards the top
for currentA in range(self.__bottomA, self.__topA + 1):
#Start with the first B and move towards the top
@@ -59,6 +59,7 @@ class Problem29(Problem):
if currentNum not in self.unique:
self.unique.append(currentNum)
#Stop the timer
self.timer.stop()
@@ -66,47 +67,39 @@ class Problem29(Problem):
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.unique.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 number of unique values generated by a^b for {self.__bottomA} <= a < = {self.__topA} and {self.__bottomB} <= b <= {self.__topB} is {len(self.unique)}"
#Returns the lowest possible value for a
def getBottomA(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the lowest possible A")
def getBottomA(self) -> int:
self.solvedCheck("lowest a")
return self.__bottomA
#Returns the lowest possible value for a
def getTopA(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the highest possible A")
def getTopA(self) -> int:
self.solvedCheck("highest a")
return self.__topA
#Returns the lowest possible value for a
def getBottomB(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the lowest possible B")
def getBottomB(self) -> int:
self.solvedCheck("lowest b")
return self.__bottomB
#Returns the lowest possible value for a
def getTopB(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the highest possible B")
def getTopB(self) -> int:
self.solvedCheck("highest b")
return self.__topB
#Returns a list of all unique values for a^b
def getUnique(self) -> list:
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see list of unique values")
self.solvedCheck("unique values for a^b")
return self.unique
#Returns the number of unique values for a^b
def getNumUnique(self) -> int:
self.solvedCheck("number of unique values for a^b")
return len(self.unique)
""" Results: