
16 Aug
2008
16 Aug
'08
3:53 p.m.
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)