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/Problem24.py
|
||||
#Matthew Ellison
|
||||
# Created: 03-24-19
|
||||
#Modified: 07-19-20
|
||||
#Modified: 10-30-20
|
||||
#What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
||||
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
|
||||
"""
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Stopwatch import Stopwatch
|
||||
from Unsolved import Unsolved
|
||||
import Algorithms
|
||||
|
||||
@@ -50,22 +49,26 @@ class Problem24(Problem):
|
||||
self.timer.start()
|
||||
|
||||
#Get all permutations of the string
|
||||
permutations = Algorithms.getPermutations(self.__nums)
|
||||
self.permutations = Algorithms.getPermutations(self.__nums)
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
#Save the results
|
||||
self.result = "The 1 millionth permutation is " + str(permutations[self.__neededPerm - 1])
|
||||
|
||||
#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()
|
||||
self.permutations.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")
|
||||
return f"The 1 millionth permutation is {self.permutations[self.__neededPerm - 1]}"
|
||||
#Returns a list with all of the permutations
|
||||
def getPermutationsList(self) -> list:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
@@ -81,15 +84,6 @@ class Problem24(Problem):
|
||||
|
||||
|
||||
|
||||
#This calls the appropriate functions if the script is called stand alone
|
||||
if __name__ == "__main__":
|
||||
problem = Problem24()
|
||||
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 1 millionth permutation is 2783915460
|
||||
It took an average of 7.147 seconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user