99-haskell-problems/Problems 21-28/problem_26.hs

11 lines
261 B
Haskell
Raw Normal View History

2024-05-25 19:28:16 -05:00
combinations :: Int -> [a] -> [[a]]
combinations 0 _ = []
combinations _ [] = []
combinations n (hd : tl) = with ++ without
where
with =
if n == 1
then [[hd]]
else [(hd :)] <*> combinations (n - 1) tl
without = combinations n tl