120
 правок
Изменения
→permutations
==subsequences==
==permutations==
 permutations :: List a -> List (List a)
 permutations Nil = Nil
 permutations (Cons x Nil) = (Cons (Cons x Nil) Nil)
 permutations (Cons x xs) = insertAtEveryPosForList (permutations xs) x
 	where
 	insertAtEveryPos :: List a -> a -> Nat -> List (List a)
 	insertAtEveryPos str elem Zero = Cons (insert Zero elem Nil str) Nil
 	insertAtEveryPos str elem pos = (insertAtEveryPos str elem (pos -. natOne)) ++ (Cons (insert pos elem Nil str) Nil)
 	insertAtEveryPosForList :: List (List a) -> a -> List (List a)
 	insertAtEveryPosForList (Cons x Nil) elem = insertAtEveryPos x elem (length x)
 	insertAtEveryPosForList (Cons x xs) elem = (insertAtEveryPosForList xs elem) ++ (insertAtEveryPos x elem (length x))
==А так же==
* Дают тип какого-нибудь foldr и просят написать какой-нибудь foldr.