Hello how are you? I have a challenge https://www.codewars.com/kata/53e57dada0cb0400ba000688/solutions/python and I've stuck on it for a 2 days, I created the first solution but it was slow(using itertools.permutations), and then I've make this block of code.
import math
def listPosition(word):
n = 0
wlsort = list(word)
wlsort.sort()
wcopy = word
while wcopy:
for i in range(wlsort.index(wcopy[0])):
n += math.factorial(len(wlsort) - 1)
wlsort.pop(wlsort.index(wcopy[0]))
wcopy = wcopy[1:]
return n + 1
but it doesn't work with words like test bookkeeper, Do you have any hints, or idea on how to solve it?
I think my problem is that when I have a word like car it will brute-force it like ->
acr, arc...
and if i have caar it will brute-force it like ->
aacr, aarc and it doesn't do acar because it is brute-forcing alphabetically.