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
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
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]) :
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