We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sequence Equation
Sequence Equation
Sort by
recency
|
1479 Discussions
|
Please Login in order to post a comment
python3
Python 3
Ok, this one took me a long time. I had to drop the mentality of "Arrays start at 0" and replace it with "Arrays start at 1".
After that, it was just a "position of the value at the N position".
def permutationEquation(p): # Write your code dic={value:index+1 for index,value in enumerate(p)} out=[] for i in range(1,len(p)+1): x=dic[i] y=dic[x] out.append(y) return out
Python: def permutationEquation(p): return [(p.index(p.index(i)+1))+1 for i in range(1, len(p)+1)]
can anyone have simple explaination?