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 @@
|
||||
#ProjectEuler/Python/Problem26.py
|
||||
#Matthew Ellison
|
||||
# Created: 07-29-19
|
||||
#Modified: 07-19-20
|
||||
#Modified: 10-30-20
|
||||
#Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
|
||||
"""
|
||||
@@ -23,9 +23,7 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Stopwatch import Stopwatch
|
||||
from Unsolved import Unsolved
|
||||
import Algorithms
|
||||
|
||||
|
||||
class Problem26(Problem):
|
||||
@@ -84,11 +82,9 @@ class Problem26(Problem):
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
#Print the results
|
||||
self.result = "The longest cycle is " + str(self.longestCycle) + " digits long" + "\nIt is started with the number " + str(self.longestNumber)
|
||||
|
||||
#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()
|
||||
@@ -96,6 +92,13 @@ class Problem26(Problem):
|
||||
self.longestNumber = 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 longest cycle is {self.longestCycle} digits long\n" \
|
||||
f"It is started with the number {self.longestNumber}"
|
||||
#Returns the length of the longest cycle
|
||||
def getLongestCycle(self) -> int:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
@@ -110,15 +113,6 @@ class Problem26(Problem):
|
||||
return self.longestNumber
|
||||
|
||||
|
||||
#This calls the appropriate functions if the script is called stand along
|
||||
if __name__ == "__main__":
|
||||
problem = Problem26()
|
||||
print(problem.getDescription()) #Print the description
|
||||
problem.solve() #Call the function that answers the problem
|
||||
#Print the results
|
||||
print(problem.getResult())
|
||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||
|
||||
""" Results:
|
||||
The longest cycle is 982 digits long
|
||||
It is started with the number 983
|
||||
|
||||
Reference in New Issue
Block a user