diff --git a/alternative.hs b/alternative.hs index 94b2813..6a0783c 100644 --- a/alternative.hs +++ b/alternative.hs @@ -1,8 +1,47 @@ +import Data.List +import Control.Applicative + + + 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) ] + , x <- combinations (n-1) (drop (i+1) xs)] +firstpos xs = [x | x <- xs, head x == 1 ] +secondpos xs = [x | x <- xs, (head (tail x)) == 2 ] + +showall xs = [y | x <- xs, y <-x, y ] + +each xs stu = [checkindividual y stu | y <- x,x <-xs] + +studentstruct ss = [(x,[x]) | x <- ss] + +fixstruct index student ss = do + let (fh,_:sh) = splitAt (index - 1) ss + fh ++ student : sh + +checkindividual lookingfor currentstudent + |(elem lookingfor $ snd currentstudent )== True = True + |otherwise = False + + + + + + +groupedTogether xs ys = [ y : ys | y <- xs, (not (elem y ys))] + +--checkeach xs cur +-- | (length xs) == numbuniquegroups = xs +-- | [ | (a,b,_,_) <- xs, a != b] +--buildassignmnet xs = [x:[] | x <- xs ] + +--eliminate xs +-- | (length xs) == numbuniquegroups/8 = xs +-- | +--capture :: Ord => [a] -> [b] -> Int +capture xs ys = length [x | x <- xs,(not (elem x ys))] -capture :: Ord => [a] -> [b] -> Int -capture xs ys = length [x | x<-cs, elem x ys] +x = combinations 4 [1..10] +--capture x [] diff --git a/mattsjunk.hs b/mattsjunk.hs index 9b1bae4..966ae83 100644 --- a/mattsjunk.hs +++ b/mattsjunk.hs @@ -1,3 +1,4 @@ +type StudentStruct = [(Integer,[Int])] {- Takes list of total students [1..howevermany] Outputs a list of tuples first element being the student ID number @@ -5,10 +6,10 @@ for storing the students already been grouped with -} --studentstruct :: Int => [Int] -> StudentStruct -studentstruct :: [t] -> [(t, [t])] +studentstruct :: [Integer] -> StudentStruct studentstruct ss = [(x,[x]) | x <- ss] -type StudentStruct = [(Int,[Int])] + {- Short and stupid function to allow inplace element manipulation @@ -16,7 +17,7 @@ type StudentStruct = [(Int,[Int])] Index value starts at 1 not zero so studentId value 1 will give you the first student -} -fixstruct :: Int -> a -> [a] -> [a] +--fixstruct :: Integer -> a -> [a] -> [a] fixstruct index student ss = do let (fh,_:sh) = splitAt (index - 1) ss fh ++ student : sh @@ -26,7 +27,7 @@ fixstruct index student ss = do curstu = the tuple where first element is the student id and the second element is the list of already grouped students -} -addstudent :: a -> (t, [a]) -> (t, [a]) +--addstudent :: a -> (t, [a]) -> (t, [a]) addstudent s curstu = head [ (y, s: x) | let x = snd curstu , let y = fst curstu] @@ -44,19 +45,16 @@ checkindividual lookingfor currentstudent --------------------------------------------------------------------------------- -outputlist :: Int -> [[Int]] +--outputlist :: Integer -> [[Integer]] outputlist numgroup = map (drop 1) (map (:[]) [1..(numgroup)]) ---checkoutputlist (ss) lookfor ol= --- if (not . (elem curstu ol)) --- then if --- map currentstudent map lookfir `checkindividual` --- then -{- - lookfor = studentid to check - currentstudent = tuple --} -checkisinoutputlist :: StudentStruct -> Int -> [Int] -> Bool +addoutputlist groupindex stuId outlist = do + let x = stuId :(outlist !! groupindex) + let (fh,_:sh) = splitAt (groupindex - 1) outlist + fh ++ x : sh + + +--checkisinoutputlist :: StudentStruct -> Int -> [Int] -> Bool checkisinoutputlist ss curstu ol |(elem curstu ol) = True |otherwise = False @@ -77,9 +75,8 @@ checkgrouplist gl studenttuple =[ checkindividual x studenttuple | x <- gl ] n = the student id to remove l = the list of students not yet grouped -} -updategroupedlist :: Eq a => a -> [a] -> [a] -updategroupedlist n l = filter (not . (==n)) l - +updateNotGroupedList :: Eq a => a -> [a] -> [a] +updateNotGroupedList n l = filter (not . (==n)) l --------------------------------------------------------------------------------- @@ -91,5 +88,18 @@ checkmod x y = ( if mod x y == 0 else putStrLn $"Cannot pair up " ++ (show x) ++ " students into groups of " ++ show(y) ++ " across eight assignments") +addAction + :: Monad m => + [(t, [Int])] -> (t, [Int]) -> Int -> [Int] -> a -> m a + +addAction ss studTup stuId notgroupedlist= do + let newnotgroupedlist = updateNotGroupedList stuId notgroupedlist + let tempTup = addstudent stuId studTup + let newSS = fixstruct stuId tempTup ss + return + + +--addAction x (2,[2]) 1 y +