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