From 867d1115341b7dd50e6b80b367593e3543c6c44d Mon Sep 17 00:00:00 2001 From: sdwoodbury Date: Tue, 7 Oct 2014 23:22:51 -0400 Subject: [PATCH] needs fix and a print list statement --- Alternative.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Alternative.hs diff --git a/Alternative.hs b/Alternative.hs new file mode 100644 index 0000000..f6325b6 --- /dev/null +++ b/Alternative.hs @@ -0,0 +1,44 @@ +module Alternative where +import Data.List +import Control.Applicative + + +{- + Alternative.hs + Written by: Michael Schwarz Stuart Woodbury Neh Patel and Matthew Henry + + see Assignment3.hs + +-} + + +{-returns a double list of all size n combinations of list xs-} +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)] + +{-captures all groups with no two groups having students grouped more than once-} +reOccurances:: (Ord a) => [a] -> [a] -> Int +reOccurances xs ys + | length xs == 0 = 0 + | length ys == 0 = 0 + | otherwise = length [x|x <- xs, elem x ys] + +{-returns a list of all unique groupings + TODO fix type error-} +getUnique :: [[Int]] -> [[Int]] +getUnique xs + | length xs == 0 = [[]] + | otherwise = do + let x = head xs + let y = tail xs + return x : [z | z <- y, (reOccurances x z ) < 2] : [[]] + +{- + Checks if the total number of students can be split into said group size +-} +checkmod :: Int -> Int -> Bool +checkmod x y + | mod x y == 0 = True + | otherwise = False