How can I generate all the possible nondecreasing sets of the elements of a list with current length?
getSets :: [Int] -> Int -> [[Int]]
...
> getSets [0..9] 3
[[0,0,0],[0,0,1]..[3,9,9],[4,4,4]..[8,9,9],[9,9,9]]
getSets s n = filter nonDec $ replicateM n s
where nonDec xs = and $ zipWith (>=) (drop 1 xs) xs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With