
21 May
2007
21 May
'07
8:05 a.m.
geniusfat
the order does not matter and each object can be chosen only once. (snip)
In that case, with the help of Data.List.tails, one can do: threeOf :: [a] -> [(a,a,a)] threeOf xs = [ (p,q,r) | (p:ps) <- tails xs, (q:qs) <- tails ps, r <- qs ] (the r <- qs is a simpler version of (r:rs) <- tails qs) or maybe, nOf :: Int -> [a] -> [[a]] nOf _ [] = [] nOf 1 xs = map return xs nOf n (x:xs) = map (x:) (nOf (n-1) xs) ++ nOf n xs (These are fairly naive versions that just took me a few minutes, but perhaps they'll do.) -- Mark