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 @@
#Project Euler/Python/Problem8.py
#Matthew Ellison
# Created: 01-29-19
#Modified: 10-30-20
#Modified: 07-24-21
#Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
"""
73167176531330624919225119674426574742355349194934
@@ -27,7 +27,7 @@
"""
#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
@@ -45,7 +45,6 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
class Problem8(Problem):
@@ -55,14 +54,14 @@ class Problem8(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?")
self.maxNums = "" #Holds the string of the largest product
self.maxProduct = 0 #Holds the largest product of 13 numbers
#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
@@ -70,6 +69,7 @@ class Problem8(Problem):
#Start the timer
self.timer.start()
#Start at the 13th entry and multiply all single digit numbers before and including that number together
cnt = 12 #The location in the number that you are working from
for cnt in range(12, len(self.__number)):
@@ -81,37 +81,32 @@ class Problem8(Problem):
#Move to the next location
cnt += 1
#Stop the timer
self.timer.stop
self.timer.stop()
#Throw a flag to show the problem is solved
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.maxNums = ""
self.maxProduct = 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 largest product of 13 adjacent digits in the number is {self.maxProduct}\n" \
f"The numbers are: {self.maxNums}"
#Returns the string of number that produces the largest product
def getLargestNums(self) -> str:
#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 nums the produce the largest product")
self.solvedCheck("numbers that make the largest product")
return self.maxNums
#Returns the requested product
def getLargestProduct(self) -> int:
#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 requested product")
self.solvedCheck("product of the numbers")
return self.maxProduct