Skip to content

Commit

Permalink
real final
Browse files Browse the repository at this point in the history
  • Loading branch information
skididdles committed Oct 8, 2014
1 parent daa657e commit f92fae6
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions assignment3.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,37 +21,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 +64,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 +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"



Expand Down

0 comments on commit f92fae6

Please sign in to comment.