Haskell combinations and permutation

后端 未结 2 565
眼角桃花
眼角桃花 2020-12-29 11:14

I have three word in a list [\"a\",\"b\",\"c\"]. i want to find all possible combination in set 5,6 etc.

for example for set of 5 i would have

**[ [a         


        
2条回答
  •  情深已故
    2020-12-29 11:50

    replicateM does what you want:

    > import Control.Monad
    > replicateM 5 ["a", "b", "c"]
    [["a","a","a","a","a"],["a","a","a","a","b"],["a","a","a","a","c"],["a","a","a","b","a"],["a","a","a","b","b"],["a","a","a","b","c"],["a","a","a","c","a"],["a","a","a","c","b"],["a","a","a","c","c"],["a","a","b","a","a"],["a","a","b","a","b"],["a","a","b","a","c"],["a","a","b","b","a"],["a","a","b","b","b"],["a","a","b","b","c"]...]
    

提交回复
热议问题