Skip to content

Commit

Permalink
desperation
Browse files Browse the repository at this point in the history
  • Loading branch information
skididdles committed Oct 8, 2014
1 parent 9ca6c2d commit 78daa42
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 21 deletions.
45 changes: 42 additions & 3 deletions alternative.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
import Data.List
import Control.Applicative



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) ]
, x <- combinations (n-1) (drop (i+1) xs)]
firstpos xs = [x | x <- xs, head x == 1 ]
secondpos xs = [x | x <- xs, (head (tail x)) == 2 ]

showall xs = [y | x <- xs, y <-x, y ]

each xs stu = [checkindividual y stu | y <- x,x <-xs]

studentstruct ss = [(x,[x]) | x <- ss]

fixstruct index student ss = do
let (fh,_:sh) = splitAt (index - 1) ss
fh ++ student : sh

checkindividual lookingfor currentstudent
|(elem lookingfor $ snd currentstudent )== True = True
|otherwise = False






groupedTogether xs ys = [ y : ys | y <- xs, (not (elem y ys))]

--checkeach xs cur
-- | (length xs) == numbuniquegroups = xs
-- | [ | (a,b,_,_) <- xs, a != b]
--buildassignmnet xs = [x:[] | x <- xs ]

--eliminate xs
-- | (length xs) == numbuniquegroups/8 = xs
-- |
--capture :: Ord => [a] -> [b] -> Int
capture xs ys = length [x | x <- xs,(not (elem x ys))]

capture :: Ord => [a] -> [b] -> Int
capture xs ys = length [x | x<-cs, elem x ys]

x = combinations 4 [1..10]
--capture x []
46 changes: 28 additions & 18 deletions mattsjunk.hs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
type StudentStruct = [(Integer,[Int])]
{-
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 :: [Integer] -> StudentStruct
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 :: Integer -> a -> [a] -> [a]
fixstruct index student ss = do
let (fh,_:sh) = splitAt (index - 1) ss
fh ++ student : sh
Expand All @@ -26,7 +27,7 @@ fixstruct index student ss = do
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 :: a -> (t, [a]) -> (t, [a])
addstudent s curstu = head [ (y, s: x) | let x = snd curstu , let y = fst curstu]


Expand All @@ -44,19 +45,16 @@ checkindividual lookingfor currentstudent

---------------------------------------------------------------------------------

outputlist :: Int -> [[Int]]
--outputlist :: Integer -> [[Integer]]
outputlist numgroup = map (drop 1) (map (:[]) [1..(numgroup)])

--checkoutputlist (ss) lookfor ol=
-- if (not . (elem curstu ol))
-- then if
-- map currentstudent map lookfir `checkindividual`
-- then
{-
lookfor = studentid to check
currentstudent = tuple
-}
checkisinoutputlist :: StudentStruct -> Int -> [Int] -> Bool
addoutputlist groupindex stuId outlist = do
let x = stuId :(outlist !! groupindex)
let (fh,_:sh) = splitAt (groupindex - 1) outlist
fh ++ x : sh


--checkisinoutputlist :: StudentStruct -> Int -> [Int] -> Bool
checkisinoutputlist ss curstu ol
|(elem curstu ol) = True
|otherwise = False
Expand All @@ -77,9 +75,8 @@ checkgrouplist gl studenttuple =[ checkindividual x studenttuple | x <- gl ]
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

updateNotGroupedList :: Eq a => a -> [a] -> [a]
updateNotGroupedList n l = filter (not . (==n)) l
---------------------------------------------------------------------------------


Expand All @@ -91,5 +88,18 @@ checkmod x y = ( if mod x y == 0
else putStrLn $"Cannot pair up " ++
(show x) ++ " students into groups of "
++ show(y) ++ " across eight assignments")
addAction
:: Monad m =>
[(t, [Int])] -> (t, [Int]) -> Int -> [Int] -> a -> m a

addAction ss studTup stuId notgroupedlist= do
let newnotgroupedlist = updateNotGroupedList stuId notgroupedlist
let tempTup = addstudent stuId studTup
let newSS = fixstruct stuId tempTup ss
return


--addAction x (2,[2]) 1 y



0 comments on commit 78daa42

Please sign in to comment.