
3 Apr
2013
3 Apr
'13
12:38 p.m.
http://stackoverflow.com/questions/8940470/algorithm-for-finding-numerical-p...
How would you rewrite this into Haskell? The code snippet is in Scala.
/** example: index:=15, list:=(1, 2, 3, 4) */ def permutationIndex (index: Int, list: List [Int]) : List [Int] = if (list.isEmpty) list else { val len = list.size // len = 4 val max = fac (len) // max = 24 val divisor = max / len // divisor = 6 val i = index / divisor // i = 2 val el = list (i) el :: permutationIndex (index - divisor * i, list.filter (_ != el)) }