Skip to content

Commit

Permalink
Add la1 grade script
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne committed Oct 30, 2024
1 parent f1de05e commit 9c5f8fe
Showing 1 changed file with 314 additions and 0 deletions.
314 changes: 314 additions & 0 deletions src/la1/la1Grading.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
val score = 0.0;
fun check (a,b,score) = if a = b then score else 0.0;
fun checkR (a,b,score) = if abs(a - b) <= 0.00001 then score else 0.0;
fun eqR (a,b) = abs(a-b) <= 0.00001;
fun abs r = if r >= 0.0 then r else ~r;
fun checkRList ([],[],score) = score
| checkRList ([],x::xs,_) = 0.0
| checkRList (x::xs,[],_) = 0.0
| checkRList (x::xs,y::ys,score) = if eqR(x,y) andalso checkRList(xs,ys) then score else 0.0;

val iList = [2,6,1,7,8];
val cList = explode "wildcats";
val emptyList : int list = [];
val sList = ["Phoenix", "Little Rock", "Montgomery", "Hartford", "Denver"];
val lList = [[],[1,2,3],[4,5,6,7]];
val pList = [(1,2),(4,5),(~2,3),(8,4)];
val rList = [1.5, 2.5, 3.5];
val clList = map explode sList;

print "\ntriangle\n"; (* 1 point *)
val act = triangle(2,3,4);
val score = score + check(true,act,0.5);
val act = triangle(3,1,1);
val score = score + check(false,act,0.5);

print "\ntriangleR\n"; (* 1 point *)
val act = triangleR(3.2,4.1,2.5);
val score = score + check(true,act,0.5);
val act = triangleR(1.2,3.5,1.3);
val score = score + check(false,act,0.5);

print "\ncycle\n"; (* 2 points *)
val act = cycle(3,iList);
val score = score + check([7,8,2,6,1],act,0.5);
val act = implode(cycle(10,cList));
val score = score + check("ldcatswi",act,0.5);
val act = cycle(0,iList);
val score = score + check([2,6,1,7,8],act,0.5);
val act = cycle(5,emptyList);
val score = score + check([],act,0.5);

print "\nmirror\n"; (* 2 points *)
val x = mirror emptyList;
val score = score + check([],x,0.5);
val x = mirror iList;
val score = score + check([2,6,1,7,8,8,7,1,6,2],x,0.5);
val x = implode(mirror cList);
val score = score + check("wildcatsstacdliw",x,0.5);
val x = mirror [5];
val score = score + check(x, [5,5], 0.5);

print "\ngtList\n"; (* 2 points *)
val x = gtList([],4);
val score = score + check(x,[], 0.5);
val x = gtList(iList, 3);
val score = score + check(x,[6,7,8],0.5);
val x = gtList(iList, 9);
val score = score + check(x,[],0.5);
val x = gtList(iList,0);
val score = score + check(x,iList,0.5);

print "\nsuffix\n"; (* 2 points *)
val x = suffix([1,7,8],iList);
val score = score + check(x,true,0.5);
val x = suffix([1,7],iList);
val score = score + check(x,false,0.5);
val x = suffix([1,7,8],[1,7,8]);
val score = score + check(x,true,0.5);
val x = suffix(explode("cats"),cList);
val score = score + check(x,true,0.5);

print "\nget\n"; (* 2 points *)
val x = get (iList, 0);
val score = score + check(x, 2, 0.5);
val x = get (sList, 3);
val score = score + check(x, "Hartford", 0.5);
val x = get (cList, 5);
val score = score + check(x, #"a", 0.5);
val x = get (lList, 2);
val score = score + check(x, [4,5,6,7], 0.5);

print "\nsubList\n"; (* 4 points *)
val x = subList(cList, 6, 6);
val score = score + check(x, [#"t"], 1.0);
val x = implode(subList((explode "university of arizona"), 3, 8));
val score = score + check(x, "versit", 1.0);
val x = subList (iList, 1, 2);
val score = score + check(x, [6,1], 1.0);
val x = subList (sList, 0, 4);
val score = score + check(x, sList, 1.0);

print "\nreverse\n"; (* 3 points *)
val x = reverse emptyList;
val score = score + check(x, emptyList, 1.0);
val x = reverse iList;
val score = score + check(x, [8,7,1,6,2], 1.0);
val x = implode(reverse cList);
val score = score + check(x, "stacdliw", 1.0);

print "\napply\n"; (* 3 points *)
val x = apply(pList, (op -));
val score = score + check(x, [~1,~1,~5,4], 1.0);
val x = implode(apply(sList, (fn s => hd(explode s))));
val score = score + check(x, "PLMHD", 1.0);
val x = apply(rList, round);
val score = score + check(x, [2,2,4], 1.0);

print "\ncollapse\n"; (* 3 points *)
val x = collapse(iList,0,(op +));
val score = score + check(x,24,1.0);
val x = collapse(pList,1,(fn ((a,b),c) => (a+b)*c));
val score = score + check(x,324,1.0);
val x = collapse(rList,2.0,(op * ));
val score = score + checkR(x,26.25,1.0);

print "\nquicksort\n"; (* 4 points *)
val x = quicksort (op <=) iList;
val score = score + check(x, [1,2,6,7,8], 1.0);
val x = quicksort (op >=) [1,4,2,5,3,1,2,3];
val score = score + check(x, [1,1,2,2,3,3,4,5], 1.0);
val x = implode(quicksort (op <=) cList);
val score = score + check(x, "acdilstw", 1.0);
val x = quicksort (op >=) rList;

print "\nbubbleSort\n"; (* 4 points *)
val x = bubbleSort (op <=) iList;
val score = score + check(x, [1,2,6,7,8], 1.0);
val x = bubbleSort (op >=) [1,4,2,5,3,1,2,3];
val score = score + check(x, [1,1,2,2,3,3,4,5], 1.0);
val x = implode(bubbleSort (op <=) cList);
val score = score + check(x, "acdilstw", 1.0);
val x = bubbleSort (op >=) rList;

print "\ninsertionSort\n"; (* 4 points *)
val x = insertionSort (op <=) iList;
val score = score + check(x, [1,2,6,7,8], 1.0);
val x = insertionSort (op >=) [1,4,2,5,3,1,2,3];
val score = score + check(x, [1,1,2,2,3,3,4,5], 1.0);
val x = implode(insertionSort (op <=) cList);
val score = score + check(x, "acdilstw", 1.0);
val x = insertionSort (op >=) rList;

print "\nsubstring\n"; (* 3 points *)
val x = substring "zon" "arizona";
val score = score + check(x, true, 1.0);
val x = substring "niva" "University";
val score = score + check(x, false, 1.0);
val x = substring "frog" "frog";
val score = score + check(x, true, 1.0);

print "\nindexOf\n"; (* 2 points *)
val x = indexOf 5 [];
val score = score + check(x, ~1, 0.5);
val x = indexOf 7 iList;
val score = score + check(x, 3, 0.5);
val x = indexOf 5 iList;
val score = score + check(x, ~1, 0.5);
val x = indexOf "Denver" sList;
val score = score + check(x, 4, 0.5);

print "\ndec2BaseN\n"; (* 3 points *);
val act = dec2baseN 2 82;
val score = score + check("1010010", act, 1.0);
val act = dec2baseN 8 100;
val score = score + check("144", act, 1.0);
val act = dec2baseN 3 44;
val score = score + check("1122", act, 1.0);

print "\ndropNth\n"; (* 3 points *);
val x = dropNth 2 [1,2,3,4,5];
val score = score + check(x, [1,3,5], 1.0);
val x = dropNth 4 emptyList;
val score = score + check(x, emptyList, 1.0);
val x = implode(dropNth 3 cList);
val score = score + check(x, "widcts", 1.0);

print "\nflatten\n"; (* 2 points *)
val x = flatten lList;
val score = score + check(x, [1,2,3,4,5,6,7], 1.0);
val x = implode(flatten clList);
val score = score + check(x, "PhoenixLittle RockMontgomeryHartfordDenver", 1.0);

print "\ncondenseLists\n"; (* 2 points *)
val x = condenseLists (op +) 0 lList;
val score = score + check(x, [0,6,22], 1.0);
val x = condenseLists (fn (c,s) => ord c + s) 0 clList;
val score = score + check(x, [0,0,0,0,0], 1.0);

print "\nremove\n"; (* 2 points *)
val x = remove (fn n => n mod 3 = 0) iList;
val score = score + check(x, [2,1,7,8], 1.0);
val x = implode(remove (fn c => c = #"w" orelse c = #"s") cList);
val score = score + check(x, "ildcat", 1.0);

print "\ntriplist\n"; (* 2 points *)
val x = triplist iList;
val score = score + check(x, [2,2,2,6,6,6,1,1,1,7,7,7,8,8,8], 1.0);
val x = implode(triplist cList);
val score = score + check(x "wwwiiillldddcccaaatttsss", 1.0);

print "\nrepeat\n"; (* 3 points *)
val x = repeat iList 2;
val score = score + check(x, [2,6,1,7,8,2,6,1,7,8], 1.0);
val x = implode(repeat cList 5);
val score = socre + check(x, "wildcatswildcatswildcatswildcatswildcats", 1.0);
val x = repeat emptyList 5;
val score = score + check(x, emptyList, 1.0);

print "\nfilterApply\n"; (* 2 points *)
val x = filterApply iList (fn n => n mod 3 = 2) (fn x => x + 1);
val score = score + check(x, [3,6,1,7,9], 1.0);
val x = implode(filterApply cList (fn (c) => c = c"a") (fn c => chr(ord(c + 1))));
val score = score + (checkx, "wildcbts", 1.0);

print "\narithSeq\n"; (* 3 points *)
val x = arithSeq 0 5 3;
val score = score + check(x, [0,5,10], 1.0);
val x = arithSeq 10, ~3, 5;
val score = score + check(x, [10, 7, 4, 1, ~2], 1.0);
val x = arithSeq 5 0 6;
val score = score + check(x, [5,5,5,5,5,5], 1.0);

print ("\nelement\n"); (* 2 points *)
val x = element 3 iList;
val score = score + check(x, false, 0.5);
val x = element 7 iList;
val score = score + check(x, true, 0.5);
val x = element 6 emptyList;
val score = score + check(x, false, 0.5);
val x = element #"i" cList;
val score = score + check(x, true, 0.5);

print("\nisSet\n"); (* 2 points *)
val score = score + check(isSet iList, true, 0.5);
val score = score + check(isSet emptyList, true, 0.5);
val score = score + check(isSet (explode "banana"), false, 0.5);
val score = score + check(isSet sList, true, 0.5);

fun qs _ [] = []
| qs _ [x] = [x]
| qs f l =
let
fun pivot p = foldr (fn (y,(lt, gte)) => if f(y,p) then (y::lt, gte) else (lt, y::gte)) ([], []);
val (l1, l2) = pivot (hd l) (tl l);
in
((qs f l1) @ [hd l] @ (qs f l2))
end;

fun equal([],[]) = true
| equal([],x::xs) = false
| equal(x::xs,[]) = false
| equal(x::xs,y::ys) = x=y andalso equal(xs,ys);

fun same (l1, l2) =
let
l1_sorted = qs (op <=) l1
l2_sorted = qs (op <=) l2
in
equal(l1_sorted, l2_sorted)
end;

val iSet1 = [1,2,3,4,5];
val iSet2 = [1,3,5,7,9,11,13];
val cSet1 = explode "arizon";
val cSet2 = explode "universty";

fun checkSets (set1, set2, score) = if same(set1, set2) then score else 0.0;


print("\nunion\n"); (* 2 points *)
val score = score + checkSets(union(iSet1,iSet2),[1,2,3,4,5,7,9,11,13],0.5);
val score = score + checkSets(union(iSet1,[]), iSet1, 0.5);
val score = score + checkSets(union(cSet1,cSet2),(explode "arizonuvesty"),0.5);
val score = score + checkSets(union([],cSet1),cSet1,0.5);

print ("\nintersection\n"); (* 2 points *)
val score = score + checkSets(intersection(iSet1,iSet2), [1,3,5], 0.5);
val score = score + checkSets(intersection(iSet1,[]), [], 0.5);
val score = score + checkSets(intersection(cSet1,cSet2), explode "rin", 0.5);
val score = score + checkSets(intersection([],cSet1), [], 0.5);

print("\ndifference\n"); (* 2 points *)
val score = score + checkSets(difference(iSet1,iSet2),[2,4],0.5);
val score = score + checkSets(difference(iSet1,[]), iSet1, 0.5);
val score = score + checkSets(difference(cSet1,cSet2),(explode "azo"),0.5);
val score = score + checkSets(difference([],cSet1),[],0.5);

print ("\xor\n"); (* 2 points *)
val score = score + checkSets(xor(iSet1,iSet2), [2,4,7,9], 0.5);
val score = score + checkSets(xor(iSet1,[]), iSet1, 0.5);
val score = score + checkSets(xor(cSet1,cSet2), explode "azouvesty", 0.5);
val score = score + checkSets(xor([],cSet1), cSet1, 0.5);

print ("\powerset\n"); (* 4 points *)
val score = score + checkSets(powerset([1,2]), [[],[1],[2],[1,2]], 1.0);
val score = score + checkSets(powerset(emptySet), [[]], 1.0);
val score = score + checkSets(powerset([1,2,3]), [[],[1],[2],[3],[1,2],[2,3],[1,3],[1,2,3]], 1.0);
val score = score + checkSets(powerset(["A"]), [[],["A"]], 1.0);
















0 comments on commit 9c5f8fe

Please sign in to comment.