John D. Ramsdell wrote:

Straight forward permation algorithm.

permutations :: Int -> [[Int]]
permutations n
    | n <=  0 = []
    | n == 1 = [[0]]

Btw. I think that case is redundant.

    | otherwise =
        concatMap (insertAtAllPos (n - 1)) (permutations (n - 1))
    where
      insertAtAllPos x [] = [[x]]
      insertAtAllPos x (y : l) =
          (x : y : l) : map (y :) (insertAtAllPos x l)

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to