permutationIndex :: Int → [Int] → [Int]
permutationIndex [] = []
permutationIndex xs =
let len = length xs
max = fac len
divisor = max / len
i = index / divisor
el = xs !! i
in permutationIndex (index - divisor * i) (filter (!= el) xs)
Of course, this is not very efficient, because you're using lists, and attempting to index into them and measure their lengths. Perhaps a different data structure is in order.
Thanks
Tom Davie
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe