From f92fae6398028afc7b513c05416ceb64e26de5af Mon Sep 17 00:00:00 2001 From: Matt Henry Date: Tue, 7 Oct 2014 22:24:02 -0400 Subject: [PATCH] real final --- assignment3.hs | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/assignment3.hs b/assignment3.hs index fcf3e61..c7e3ad5 100644 --- a/assignment3.hs +++ b/assignment3.hs @@ -2,9 +2,16 @@ import System.Environment import System.IO import Data.List import Control.Applicative +import Data.List.Split +{- + THIS DOES NOT WORK + :( + checkmod does though +-} +-------------------------------------------------------------------------------------- {- Combinations gets all possible combinations of a list of numbers http://www.haskell.org/haskellwiki/99_questions/Solutions/26 @@ -14,29 +21,29 @@ 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)] - + -------------------------------------------------------------------------------------- {- firstpos gets the first list if the item is 1 -} firstpos xs = [x | x <- xs, head x == 1 ] - +-------------------------------------------------------------------------------------- {- scondpos gets the first list with first item 2 -} secondpos xs = [x | x <- xs, (head (tail x)) == 2 ] - +-------------------------------------------------------------------------------------- {- Print all the lists within combinations by taking them out of the list -} showall xs = [y | x <- xs, y <-x, y ] - +-------------------------------------------------------------------------------------- {- creates a list of tuples containing an int and a list of other ints meant to contain the student and the students it has been grouped with -} studentstruct ss = [(x,[x]) | x <- ss] - +-------------------------------------------------------------------------------------- {- Remakes the studentstruct so that it is recreated essentially the fix for not being able to pass by reference @@ -44,7 +51,7 @@ studentstruct ss = [(x,[x]) | x <- ss] fixstruct index student ss = do let (fh,_:sh) = splitAt (index - 1) ss fh ++ student : sh - +-------------------------------------------------------------------------------------- {- studentstruct !! number gives you currentstudent looking for is the student to check for @@ -57,7 +64,7 @@ checkindividual lookingfor currentstudent |otherwise = False - +-------------------------------------------------------------------------------------- {- Checks if the total number of students can be split into said group size -} @@ -65,13 +72,31 @@ checkmod :: Int -> Int -> Bool checkmod x y | mod x y == 0 = True | otherwise = False - + -------------------------------------------------------------------------------------- {- capture retrieves a list within another list if the element is in the first list -} capture xs ys = length [x | x <- xs,(not (elem x ys))] +-------------------------------------------------------------------------------------- +{- + 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" +-------------------------------------------------------------------------------------- +{- + split list makes a bunch of sublists +-} +splitList :: Int -> Int -> [[Int]] +splitList b a + | a == 0 = [] + | otherwise = chunksOf a [1..b] - +-------------------------------------------------------------------------------------- --http://www.reddit.com/r/haskell/comments/1vras3/haskell_io_how_to_read_numbers/ @@ -89,9 +114,7 @@ main = else do - putStrLn $"Cannot pair up " ++ - show(students) ++ " students into groups of " - ++ show(grpsize) ++ " across eight assignments" + putStrLn $"Cannot pair up " ++ show(students) ++ " students into groups of " ++ show(grpsize) ++ " across eight assignments"