diff --git a/MyModules.hs b/MyModules.hs new file mode 100644 index 0000000..b7d401e --- /dev/null +++ b/MyModules.hs @@ -0,0 +1,114 @@ +module MyModules where + + +{- + Takes list of total students [1..howevermany] + Outputs a list of tuples first element being the student ID number + Second being a list + for storing the students already been grouped with +-} +--studentstruct :: Int => [Int] -> StudentStruct +studentstruct :: [t] -> [(t, [t])] +studentstruct ss = [(x,[x]) | x <- ss] + +type StudentStruct = [(Int,[Int])] + +{- + Short and stupid function to allow inplace element manipulation + for a list Not the most elegant but it does what it needs + Index value starts at 1 not zero so studentId value 1 will give you + the first student +-} +fixstruct :: Int -> a -> [a] -> [a] +fixstruct index student ss = do + let (fh,_:sh) = splitAt (index - 1) ss + fh ++ student : sh + +{- + s = the student to add + 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 s curstu = head [ (y, s: x) | let x = snd curstu , let y = fst curstu] + +outputlist :: Int -> [[Int]] +outputlist numgroup = map (drop 1) (map (:[]) [1..(numgroup)]) + + + +{- + Updates the current list of already grouped + used for generating groups for assignment + 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 + +{- + studentstruct !! number gives you currentstudent + looking for is the student to check for + returns true if student has already been grouped with this student + otherwise will add student to group + TODO needs to the update grouped already list +-} +checkindividual :: Eq a => a -> (t, [a]) -> Either (t, [a]) Bool +checkindividual lookingfor currentstudent = + case elem lookingfor $ snd currentstudent of + True -> Right True + False -> Left $ addstudent lookingfor currentstudent + +{- +altcheckind lookingfor currentstudent = + (if elem lookingfor $ snd currentstudent + then do { + return + } + else + do { + addstudent lookingfor currentstudent + } +-} + +--TODO make output True for true conidtion +--Checks if the total number of students can be split into said group size +checkmod :: Int -> Int -> Bool +checkmod x y + | x `mod` y == 0 = True + | otherwise = False +{- + should iterate entire list of students + call checkindividual lfor = student to look for + x is just the size of list +-} +checkall :: Eq a => [(t, [a])] -> a -> [Either (t, [a]) Bool] +checkall students lfor = [ checkindividual lfor (students !! index )| index <- [1..((length students )-1)]] + +{- + Keep running till current group size is filled + lookingfor +-} +--groupstudent lookingfor currentstudent gl= do +-- addstudent lookingfor currentstudent +-- updategroupedlist lookingfor gl + + + +--groupassignment ss y = do + --let notgrouped = [1..(length ss)] + -- + + + +program x y = do + let ss = studentstruct [1..x] + checkmod x y --last statement must be expression in so haskell doesnt bitch + --groupassignment ss y + + + + + + + diff --git a/practiceMain.hs b/practiceMain.hs index e5ee8ff..00536e0 100644 --- a/practiceMain.hs +++ b/practiceMain.hs @@ -1,40 +1,10 @@ - import System.Environment import System.IO import Data.List import System.IO import Data.List.Split +import MyModules ----------------------------------------------------------------------------------- ---TODO make output True for true conidtion ---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 ------------------------------------------------------------------------------------ ---split list makes a bunch of sublists -splitList :: Int -> Int -> [[Int]] -splitList b a - | a == 0 = [] - | otherwise = chunksOf a [1..b] - ----------------------------------------------------------------------------- ---takes [[final list of student groups]] [student list] group size ---listGen perhaps will build a list of groups, determine if it can continue or not and if ---the conditions have been met, and then print out the output -listGen :: [[Int]] -> [Int] -> Int -> IO () -listGen endList students groupSize - | (length endList) == ((length students) `div` groupSize) * 8 = putStrLn "Success" - | otherwise = putStrLn "Can not group everyone up in groups that size 8 times" ----------------------------------------------------------------------------------- - ---http://www.reddit.com/r/haskell/comments/1vras3/haskell_io_how_to_read_numbers/ - - ---hey matt i finally did something usefull. so for now let the start of the program be ---a conditional. checkmod i made a boolean. if true we do the calculation. if false, ---don't do anything main :: IO () main = @@ -45,12 +15,10 @@ main = let grpsize = read(head $tail args) :: Int if checkmod students grpsize - then - listGen (splitList students grpsize) [1..students] grpsize + then putStrLn "do stuff" else - do - putStrLn "Can not group everyone up in groups that size" + putStrLn "Can not group everyone up in groups that size"