-
Notifications
You must be signed in to change notification settings - Fork 1
/
Alternative.hs
49 lines (38 loc) · 1.29 KB
/
Alternative.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
-}
{-produces all combinations-}
--http://www.haskell.org/haskellwiki/99_questions/Solutions/26
combinations :: Int -> [a] -> [[a]]
combinations 0 _ = [[]]
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
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
--http://stackoverflow.com/questions/932639/haskell-cant-use-map-putstrln
mapM_ :: Monad m => (a -> m b) -> [a] -> m ()