From 0908e5a5f0976c189a734230125434eeef990db7 Mon Sep 17 00:00:00 2001 From: mschwarz1 Date: Tue, 7 Oct 2014 16:43:52 -0400 Subject: [PATCH 1/7] Update backup.c --- backup.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/backup.c b/backup.c index 98095af..78f7823 100644 --- a/backup.c +++ b/backup.c @@ -41,17 +41,53 @@ int contains(Array *a, int target) { } return 0; +} + +int validPartner(Array *a, int perspectivePartner, int** currentGroups) { + + int x; + int y; + for (x = 0; x < sizeof(currentGroups)/sizeof(currentGroups[0]); x++) { + for (y = 0; x < sizeof(currentGroups[0])/sizeof(currentGroups[0][0]); x++ ) { + if (currentGroups[x][y] == validPartner) { + return 0; + } + } + } + + if (contains(a, perspectivePartner)) { + + return 0; + } + + return 1; + + + } int main (int argc, char *argv[]) { - int groupsize = argv[2]; - int studentAmount = argv[1]; + + + + + int groupsize = atoi(argv[2]); + int studentAmount = atoi(argv[1]); Array students[studentAmount]; - int i; - printf("The groupsize %d The students %d", groupsize, studentAmount); + int currentGroups[studentAmount][groupsize]; + int x; + for (x = 0; x < studentAmount; x++) { + initArray(&students[x], 1); + } + +int i; + + printf("The groupsize %d The students %d \n", groupsize, studentAmount); + + for (i = 0; i < 8; i++ ) { printf("Assignment %d ", i+1); @@ -61,17 +97,22 @@ int main (int argc, char *argv[]) { printf("( %d", j+1); int k; for (k = 0; k < studentAmount; k++) { - - if ((!contains(students[j], k)) && counter < groupsize) { - insertArray(students[j], k); - insertArray(students[k], j); + + if ((validPartner(&students[j], k, currentGroups)) && counter+1 < groupsize) { + //currentGroups[0][0] = 10; + insertArray(&students[j], k); + insertArray(&students[k], j); counter= counter + 1; - printf(", %d", k+1); + printf(", %d", k); - } + } + } - printf(") /n"); + counter = 0; + printf(")"); } + printf(" \n"); } + } From 9ca6c2df0d6528537d8bc7bbbee81d9bc305b81b Mon Sep 17 00:00:00 2001 From: Matt Henry Date: Tue, 7 Oct 2014 19:05:49 -0400 Subject: [PATCH 2/7] nice way --- alternative.hs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 alternative.hs diff --git a/alternative.hs b/alternative.hs new file mode 100644 index 0000000..94b2813 --- /dev/null +++ b/alternative.hs @@ -0,0 +1,8 @@ +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) ] + +capture :: Ord => [a] -> [b] -> Int +capture xs ys = length [x | x<-cs, elem x ys] + From 78daa423b38440eb8e323ff0e249f9ee6991b2e4 Mon Sep 17 00:00:00 2001 From: Matt Henry Date: Tue, 7 Oct 2014 21:37:11 -0400 Subject: [PATCH 3/7] desperation --- alternative.hs | 45 ++++++++++++++++++++++++++++++++++++++++++--- mattsjunk.hs | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/alternative.hs b/alternative.hs index 94b2813..6a0783c 100644 --- a/alternative.hs +++ b/alternative.hs @@ -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 [] diff --git a/mattsjunk.hs b/mattsjunk.hs index 9b1bae4..966ae83 100644 --- a/mattsjunk.hs +++ b/mattsjunk.hs @@ -1,3 +1,4 @@ +type StudentStruct = [(Integer,[Int])] {- Takes list of total students [1..howevermany] Outputs a list of tuples first element being the student ID number @@ -5,10 +6,10 @@ 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 @@ -16,7 +17,7 @@ type StudentStruct = [(Int,[Int])] 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 @@ -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] @@ -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 @@ -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 --------------------------------------------------------------------------------- @@ -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 + From da96eac559e18b55946495dd593334b32493601b Mon Sep 17 00:00:00 2001 From: mschwarz1 Date: Tue, 7 Oct 2014 21:44:11 -0400 Subject: [PATCH 4/7] Putting things together --- assignment3.hs | 55 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/assignment3.hs b/assignment3.hs index fb4e8a1..25f7452 100644 --- a/assignment3.hs +++ b/assignment3.hs @@ -1,8 +1,54 @@ import System.Environment import System.IO import Data.List -import System.IO +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)] + +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))] + +x = combinations 4 [1..10] +--capture x [] --http://www.reddit.com/r/haskell/comments/1vras3/haskell_io_how_to_read_numbers/ @@ -14,14 +60,13 @@ main = progName <- getProgName let students = read(head args) :: Int --now we can use ints! let grpsize = read(head $tail args) :: Int - putStrLn "The number of stoodents aer:" + putStrLn "The number of students are:" putStrLn students - putStrLn "Teh greup siez is: " + putStrLn "The group size is: " putStrLn grpsize putStrLn "Program name is:" putStrLn progName - return (students, grpsize) - return () + From 18c0e15e9fa5af1b376d36a507f4d619e69335b2 Mon Sep 17 00:00:00 2001 From: mschwarz1 Date: Tue, 7 Oct 2014 21:53:02 -0400 Subject: [PATCH 5/7] comments --- assignment3.hs | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/assignment3.hs b/assignment3.hs index 25f7452..97132da 100644 --- a/assignment3.hs +++ b/assignment3.hs @@ -5,25 +5,52 @@ import Control.Applicative - +{- + Combinations gets all possible combinations of a list of numbers +-} 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 ] +{- + +-} each xs stu = [checkindividual y stu | y <- x,x <-xs] + +{- + 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] +{- + +-} 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 @@ -35,20 +62,11 @@ checkindividual lookingfor currentstudent 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))] x = combinations 4 [1..10] ---capture x [] --http://www.reddit.com/r/haskell/comments/1vras3/haskell_io_how_to_read_numbers/ From 30f6b19e4c86de4ef37108676af7d52f5c0ecd16 Mon Sep 17 00:00:00 2001 From: mschwarz1 Date: Tue, 7 Oct 2014 21:55:37 -0400 Subject: [PATCH 6/7] more comments --- assignment3.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assignment3.hs b/assignment3.hs index 97132da..8cf6d0b 100644 --- a/assignment3.hs +++ b/assignment3.hs @@ -59,7 +59,9 @@ checkindividual lookingfor currentstudent - +{- + +-} groupedTogether xs ys = [ y : ys | y <- xs, (not (elem y ys))] From 0583a083e6949cffdb1ddad974fbda3a6ed66b05 Mon Sep 17 00:00:00 2001 From: mschwarz1 Date: Tue, 7 Oct 2014 22:01:29 -0400 Subject: [PATCH 7/7] Update assignment3.hs --- assignment3.hs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/assignment3.hs b/assignment3.hs index 8cf6d0b..8831c69 100644 --- a/assignment3.hs +++ b/assignment3.hs @@ -57,7 +57,14 @@ checkindividual 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 + | mod x y == 0 = True + | otherwise = False {- @@ -80,13 +87,17 @@ main = progName <- getProgName let students = read(head args) :: Int --now we can use ints! let grpsize = read(head $tail args) :: Int - putStrLn "The number of students are:" - putStrLn students - putStrLn "The group size is: " - putStrLn grpsize - putStrLn "Program name is:" - putStrLn progName - + if checkmod students grpsize + then + listGen (splitList students grpsize) [1..students] grpsize + + else + do + putStrLn $"Cannot pair up " ++ + show(students) ++ " students into groups of " + ++ show(grpsize) ++ " across eight assignments" + +