120
 правок
Изменения
→permutations
==permutations==
 permutations :: List a -> List (List a)
 permutations Nil = Nil permutations (Cons x Nil) = (Cons (Cons x Nil) Nil) permutations (Cons x xsab) = insertAtEveryPosForList (permutations xs) perm Nil x 	ab where 	insertAtEveryPos :: List a -> a -> Nat -> List (List a) 	insertAtEveryPos str elem Zero = Cons (insert Zero elem      perm left m Nil str) Nil 	insertAtEveryPos str elem pos = (insertAtEveryPos str elem (pos -. natOne)) ++ map (Cons (insert pos elem Nil str) Nil)  	insertAtEveryPosForList :: List (List am) -> a -> List (List apermutations left) 	insertAtEveryPosForList      perm left m (Cons x Nilr rx) elem = insertAtEveryPos x elem (length xmap (Cons m) 	insertAtEveryPosForList $ permutations $ left ++ (Cons x xsr rx) elem = (insertAtEveryPosForList xs elem) ++ (insertAtEveryPos x elem perm (length xCons m left)r rx)
==А так же==