Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get list of all nondecreasing sets of list in haskell

Tags:

list

haskell

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]]
like image 205
ДМИТРИЙ МАЛИКОВ Avatar asked Aug 11 '11 20:08

ДМИТРИЙ МАЛИКОВ


1 Answers

getSets s n = filter nonDec $ replicateM n s
  where nonDec xs = and $ zipWith (>=) (drop 1 xs) xs
like image 89
augustss Avatar answered Sep 28 '22 07:09

augustss