# Lets the user input a number N between 1 and 10 and a number k
# at most equalt to N!, and outputs the kth permutation of {0, ..., N-1},
# using lexicographic order and counting from 1.
#
# Written by *** and Eric Martin for COMP9021
import sys
from math import factorial
provided_input = input('Enter two strictly positive integers,\n'
' the first one at most equal to 10\n'
' the second one at most equal to first one!: ')
provided_input = provided_input.split()
if len(provided_input) != 2:
print('Incorrect input, giving up.')
sys.exit()
try:
number_range = int(provided_input[0])
rank = int(provided_input[1])
if number_range <= 0 or rank <= 0 or rank > factorial(number_range):
raise ValueError
except:
print('Incorrect input, giving up.')
sys.exit()
solution = ''
# REPLACE THIS COMMENT WITH YOUR CODE
print('Lexicographically, the permutation of 0, ..., {} of rank {} is: {}'.
format(number_range - 1, rank, solution))
Resource created Thursday 15 October 2015, 12:01:42 AM, last modified Thursday 15 October 2015, 11:00:23 AM.
file: quiz_10.py