importData.List(sortBy)-- takes an inversion list and converts it to the list of permuted -- elements: decode=dec[].sortBylowHi.zip[1..]wheredecas[]=asdecas((a,_):is)=letis'=sortBylowHi(decrementGTais)indec(a:as)is'-- decrement every inversion number by 1, for every tuple in which -- the element is greater than `a`: decrementGTa=map(\(a',i)->(a',ifa'>atheni-1elsei))-- we sort by the inversion number, low to high. For elements with -- the same inversion number, we say that the greater element tuple -- should go before a lesser element: lowHi(a,i)(a',i')|i==i'=ifa>a'thenLTelseGT|otherwise=compareii'
It’s not the prettiest code I’ve written, but it’s pretty straight-forward and
concise. Thanks for looking!