Re: [Haskell-cafe] algorithm-for-finding-numerical-permutation-given-lexicographic-index

2013-04-10 Thread mukesh tiwari
Hi Lone Just coded quickly so still there is lot of chance for improvement. {-# LANGUAGE MultiWayIf #-} import Data.List import Data.Word import Data.Bits builtin_ctz_hask :: Word32 - Word32 builtin_ctz_hask x | x == 0 = 32 | otherwise = n' - ( ( .. ) x' 1 ) where

Re: [Haskell-cafe] algorithm-for-finding-numerical-permutation-given-lexicographic-index

2013-04-09 Thread Lone Wolf
How could I use Data.Bits to implement the below C code in Haskell? http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation Compute the lexicographically next bit permutation Suppose we have a pattern of N bits set to 1 in an integer and we want the next permutation of N 1

[Haskell-cafe] algorithm-for-finding-numerical-permutation-given-lexicographic-index

2013-04-03 Thread Lone Wolf
http://stackoverflow.com/questions/8940470/algorithm-for-finding-numerical-permutation-given-lexicographic-index 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]) :

Re: [Haskell-cafe] algorithm-for-finding-numerical-permutation-given-lexicographic-index

2013-04-03 Thread Tom Davie
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