Reputation: 2579
Haskell has Data.List.permutations
permutations "abc" == ["abc","bac","cba","bca","cab","acb"]
Is there a standard library function for transformations or do you need to roll your own?
transformations "ab" == ["aa","ab","ba","bb"]
The Ruby way is:
x.repeated_permutation(x.length)
Upvotes: 2
Views: 122
Reputation: 76260
You are looking for replicateM
in the Control.Monad
module:
replicateM 2 "ab"
-- ["aa","ab","ba","bb"]
AFAIK they are permutations with repetitions from the alphabet ['a', 'b']
.
Upvotes: 5