mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Updated all problems to use fstrings and results()
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#Project Euler/Python/Problem8.py
|
||||
#Matthew Ellison
|
||||
# Created: 01-29-19
|
||||
#Modified: 07-18-20
|
||||
#Modified: 10-30-20
|
||||
#Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
||||
"""
|
||||
73167176531330624919225119674426574742355349194934
|
||||
@@ -45,7 +45,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Stopwatch import Stopwatch
|
||||
from Unsolved import Unsolved
|
||||
|
||||
|
||||
@@ -85,18 +84,23 @@ class Problem8(Problem):
|
||||
#Stop the timer
|
||||
self.timer.stop
|
||||
|
||||
#Save the results
|
||||
self.result = "The largest product of 13 adjacent digits in the number is " + str(self.maxProduct) + "\nThe numbers are: " + self.maxNums
|
||||
|
||||
#Throw a flag to show the problem is solved
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
super().reset()
|
||||
maxNums = ""
|
||||
maxProduct = 0
|
||||
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")
|
||||
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
|
||||
@@ -110,14 +114,6 @@ class Problem8(Problem):
|
||||
raise Unsolved("You must solve the problem before you can get the requested product")
|
||||
return self.maxProduct
|
||||
|
||||
#If you are running this file, automatically start the correct function
|
||||
if __name__ == '__main__':
|
||||
problem = Problem8()
|
||||
print(problem.getDescription()) #Print the description of the problem
|
||||
problem.solve() #Solve the problem
|
||||
#Print the results
|
||||
print(problem.getResult())
|
||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||
|
||||
"""Results:
|
||||
The largest product of 13 adjacent digits in the number is 23514624000
|
||||
|
||||
Reference in New Issue
Block a user