Haskell具有Data.List.permutations
permutations "abc" == ["abc","bac","cba","bca","cab","acb"]
是否有用于转换的标准库函数,或者您需要自己滚动?
transformations "ab" == ["aa","ab","ba","bb"]
Ruby的方式是:
x.repeated_permutation(x.length)
最佳答案
您正在replicateM
模块中寻找Control.Monad
:
replicateM 2 "ab"
-- ["aa","ab","ba","bb"]
AFAIK是从字母
['a', 'b']
重复的排列。