Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwoodbury committed Oct 8, 2014
2 parents ff06332 + eaecc88 commit e6b2076
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
Binary file added assignment3
Binary file not shown.
52 changes: 40 additions & 12 deletions assignment3.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
{-
Assignment3
Written by: Michael Schwarz Stuart Woodbury Neh Patel and Matthew Henry
-}
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
Expand All @@ -14,37 +26,37 @@ 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
-}
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
Expand All @@ -57,21 +69,39 @@ checkindividual lookingfor currentstudent
|otherwise = False



--------------------------------------------------------------------------------------
{-
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

--------------------------------------------------------------------------------------
{-
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/


Expand All @@ -89,9 +119,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"



Expand Down
5 changes: 5 additions & 0 deletions mattsjunk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ updateNotGroupedList :: Eq a => a -> [a] -> [a]
updateNotGroupedList n l = filter (not . (==n)) l
---------------------------------------------------------------------------------

fillgroup ol grpsize = (if (length ol) == grpsize
then




--TODO make output True for true conidtion
--Checks if the total number of students can be split into said group size
Expand Down

0 comments on commit e6b2076

Please sign in to comment.