human
Give me a code to lexicographic rank of a string and the other steps required given the following:
Lexicographic rank of a string | A utility function to find factorial of n.
A utility function to count smaller characters on right of arr [ low ].
A function to find rank of a string in all permutations of characters.
count number of chars smaller than str [ i ] fron str [ i + 1 ] to str [ len - 1 ].
Driver program to test above function"
Solution in Python:
assistant
#Here is code to lexicographic rank of a string and the other steps required.
 def fact ( n ) :
	f = 1
	while n >= 1 :
		f = f * n
		n = n - 1
	return f
def findSmallerInRight ( st , low , high ) :
	countRight = 0
	i = low + 1
	while i <= high :
		if st [ i ] < st [ low ] :
			countRight = countRight + 1
		i = i + 1
	return countRight
def findRank ( st ) :
	ln = len ( st )
	mul = fact ( ln )
	rank = 1
	i = 0
	while i < ln :
		mul = mul / ( ln - i )
		countRight = findSmallerInRight ( st , i , ln - 1 )
		rank = rank + countRight * mul
		i = i + 1
	return rank
st = " string "
print ( findRank ( st ) )