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/Problem24.py
#Matthew Ellison
# Created: 03-24-19
#Modified: 10-30-20
#Modified: 07-24-21
#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
"""
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,8 +23,7 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
import Algorithms
import StringAlgorithms
class Problem24(Problem):
@@ -34,13 +33,13 @@ class Problem24(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?")
self.permutations = []
#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
@@ -48,8 +47,10 @@ class Problem24(Problem):
#Start the timer
self.timer.start()
#Get all permutations of the string
self.permutations = Algorithms.getPermutations(self.__nums)
self.permutations = StringAlgorithms.getPermutations(self.__nums)
#Stop the timer
self.timer.stop()
@@ -58,30 +59,23 @@ class Problem24(Problem):
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
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")
def getResult(self) -> str:
self.solvedCheck("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
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the list of permutations")
self.solvedCheck("permutations")
return self.permutations
#Returns the requested permutation
def getPermutation(self) -> str:
#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 ")
self.solvedCheck("1,000,000th permutation")
return self.permutations[self.__neededPerm - 1]
""" Results: