Files
ProjectEulerPython/Problem24.py

54 lines
1.7 KiB
Python

#ProjectEuler/Python/Problem24.py
#Matthew Ellison
# Created: 03-24-19
#Modified: 03-28-19
#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) 2019 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from Stopwatch import Stopwatch
import Algorithms
__neededPerm = 1000000 #The number of the permutation that you need
def Problem24():
#Setup the variables
nums = "0123456789"
#Get all permutations of the string
permutations = Algorithms.getPermutations(nums)
#Print the results
print("The 1 millionth permutation is " + str(permutations[__neededPerm - 1]))
#This calls the appropriate functions if the script is called stand alone
if __name__ == "__main__":
timer = Stopwatch()
timer.start()
Problem24()
timer.stop()
print("It took " + timer.getString() + " to run this algorithm")
""" Results:
The 1 millionth permutation is 2783915460
It took 7.363 seconds to run this algorithm
"""