From b87756b6c59d3f6c61d724d5507f58a6322879eb Mon Sep 17 00:00:00 2001 From: sdwoodbury Date: Tue, 7 Oct 2014 23:35:39 -0400 Subject: [PATCH] supposedly prints out the good list of lists --- Alternative.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Alternative.hs b/Alternative.hs index f6325b6..87a7cb6 100644 --- a/Alternative.hs +++ b/Alternative.hs @@ -12,11 +12,12 @@ import Control.Applicative -} -{-returns a double list of all size n combinations of list xs-} +{-produces all combinations-} +--http://www.haskell.org/haskellwiki/99_questions/Solutions/26 combinations :: Int -> [a] -> [[a]] combinations 0 _ = [[]] -combinations n xs = [ xs !! i : x | i <- [0..(length xs)-1] - , x <- combinations (n-1) (drop (i+1) xs)] +combinations _ [] = [] +combinations n (x:xs) = (map (x:) (combinations (n-1) xs)) ++ (combinations n xs) {-captures all groups with no two groups having students grouped more than once-} reOccurances:: (Ord a) => [a] -> [a] -> Int @@ -42,3 +43,7 @@ checkmod :: Int -> Int -> Bool checkmod x y | mod x y == 0 = True | otherwise = False + +--http://stackoverflow.com/questions/932639/haskell-cant-use-map-putstrln +mapM_ :: Monad m => (a -> m b) -> [a] -> m () +