Skip to content

Commit

Permalink
put matts junk in a module file, modivied checkmod to make it a boole…
Browse files Browse the repository at this point in the history
…an, and used it in a main method
  • Loading branch information
sdwoodbury committed Oct 7, 2014
1 parent 1e35cd0 commit fffb1fa
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 35 deletions.
114 changes: 114 additions & 0 deletions MyModules.hs
Original file line number Diff line number Diff line change
@@ -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







38 changes: 3 additions & 35 deletions practiceMain.hs
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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"



Expand Down

0 comments on commit fffb1fa

Please sign in to comment.