Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwoodbury committed Oct 7, 2014
2 parents a1e2121 + 6860b17 commit 7052c73
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 56 deletions.
77 changes: 77 additions & 0 deletions backup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <stdio.h>

// Taken from http://stackoverflow.com/questions/3536153/c-dynamically-growing-array

typedef struct {
int *array;
size_t used;
size_t size;
} Array;

void initArray(Array *a, size_t initialSize) {
a->array = (int *)malloc(initialSize * sizeof(int));
a->used = 0;
a->size = initialSize;
}


void insertArray(Array *a, int element) {
if (a->used == a->size) {
a->size *= 2;
a->array = (int *)realloc(a->array, a->size * sizeof(int));
}
a->array[a->used++] = element;
}

void freeArray(Array *a) {
free(a->array);
a->array = NULL;
a->used = a->size = 0;
}


int contains(Array *a, int target) {

int i;
for (i = 0; i < a->size; i++) {
if (a->array[i] == target) {
return 1;
}

}
return 0;

}

int main (int argc, char *argv[]) {

int groupsize = argv[2];
int studentAmount = argv[1];
Array students[studentAmount];
int i;

printf("The groupsize %d The students %d", groupsize, studentAmount);

for (i = 0; i < 8; i++ ) {

printf("Assignment %d ", i+1);
int j;
int counter = 0;
for (j = 0; j < studentAmount; j++) {
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);
counter= counter + 1;
printf(", %d", k+1);

}
}
printf(") /n");
}
}
}

78 changes: 22 additions & 56 deletions mattsjunk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ fixstruct index student ss = do
addstudent :: a -> (t, [a]) -> (t, [a])
addstudent s curstu = head [ (y, s: x) | let x = snd curstu , let y = fst curstu]


{-
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 lookingfor currentstudent
|(elem lookingfor $ snd currentstudent )== True = True
|otherwise = False

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

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

Expand All @@ -41,16 +56,20 @@ outputlist numgroup = map (drop 1) (map (:[]) [1..(numgroup)])
lookfor = studentid to check
currentstudent = tuple
-}
checkoutputlist :: StudentStruct -> Int -> [Int] -> Bool
checkisinoutputlist :: StudentStruct -> Int -> [Int] -> Bool
checkisinoutputlist ss curstu ol
|(elem curstu ol) = True
|otherwise = False

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

--checkoutputlist ss curstu ol

{-
TODO: Or these guys together
One True will make this student not able to add to this group
-}
checkgrouplist gl studenttuple = [ checkindividual x studenttuple | x <- gl ]
checkgrouplist gl studenttuple =[ checkindividual x studenttuple | x <- gl ]

{-
Updates the current list of already grouped
Expand All @@ -61,29 +80,8 @@ checkgrouplist gl studenttuple = [ checkindividual x studenttuple | x <- gl ]
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 lookingfor currentstudent
|(elem lookingfor $ snd currentstudent )== True = True
|otherwise = False

{-
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
Expand All @@ -93,37 +91,5 @@ checkmod x y = ( if mod x y == 0
else putStrLn $"Cannot pair up " ++
(show x) ++ " students into groups of "
++ show(y) ++ " across eight assignments")
{-
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






0 comments on commit 7052c73

Please sign in to comment.