Advertisement
teleias

LISP AutoGrader

Nov 18th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 4.54 KB | None | 0 0
  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;LISP Autograder;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;;                      by Austin Takechi;;;;;;;;;;
  5. ;;                      November 17, 2015;;;;;;;;;;
  6. ;;                austintakechi@gmail.com;;;;;;;;;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;;;;Use this to grade assignments easily.;;;;;;;;;
  9. ;;;;; Copy and paste this code into the   ;;;;;;;;;
  10. ;;;;; student's code. Modify the tests and;;;;;;;;;
  11. ;;;;; answers if you update them.         ;;;;;;;;;
  12. ;;;;;The final grade is out of 50, but    ;;;;;;;;;
  13. ;;;;; there are only 3 tests per case, so ;;;;;;;;;
  14. ;;;;; while the tests say 2/3, they really;;;;;;;;;
  15. ;;;;; mean 66% of 1/6th of 50 points, as  ;;;;;;;;;
  16. ;;;;; there are 6 tests.                  ;;;;;;;;;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;; Cheers! ;;;;;;;;;;;;;;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. ;A function that will tell whether two things are the same, regardless of if they are atoms or lists.
  21. (define (_eq A B)
  22.   (if (and (null? A) (null? B)) #t
  23.       (if (and (list? A) (list? B) (= (car A) (car B)) (_eq (cdr A) (cdr B))) #t
  24.           (if (equal? A B) #t #f))))
  25.  
  26. ;Sample boolean Functions used later
  27. (define (_multOf3 x) (= (modulo x 3) 0))
  28. (define (_singleDigit x) (and (> x -1) (< x 10)))
  29.  
  30. ;Defining some makeCutters to use later
  31. (define _F4 (makeCutter 4))
  32. (define _F3 (makeCutter 3))
  33. (define _F5 (makeCutter 5))
  34.  
  35.  
  36. (let(
  37.   (A1q (buildLR 12345 67890)) ;Test #1 for A
  38.   (A2q (buildLR 12345 60000)) ;Test #2 for A
  39.   (A3q (buildLR 1     60000)) ;Test #3 for A
  40.   (A1a '1290)                 ;Answer for Test #1 for A
  41.   (A2a '1200)                 ;Answer for Test #2 for A
  42.   (A3a '-1)                   ;Answer for Test #3 for A
  43.   (B1q (listMins '(2 8 7) '(5 4 4)))
  44.   (B2q (listMins '(3 -1 7) '(1 0 1)))
  45.   (B3q (listMins '(0 1 0) '(1 0 1)))
  46.   (B1a '(2 4 4))
  47.   (B2a '(1 -1 1))
  48.   (B3a '(0 0 0))
  49.   (C1q (unwind '(7 8 2 9 5 6)))
  50.   (C2q (unwind '(7 8 2 9 5)))
  51.   (C3q (unwind '(1 2 3 4 5 6 7 8)))
  52.   (C1a '(2 9 8 5 7 6))
  53.   (C2a '(2 8 9 7 5))
  54.   (C3a '(4 5 3 6 2 7 1 8))
  55.   (D1q (functionWinner _multOf3 _singleDigit '(10 20 3 4 5 6)))
  56.   (D2q (functionWinner _singleDigit _multOf3 '(10 20 3 4 5 6)))
  57.   (D3q (functionWinner _multOf3     _multOf3 '(10 20 3 4 5 6)))
  58.   (D1a 2)
  59.   (D2a 1)
  60.   (D3a 0)
  61.   (E1q (getNestedCount '(()()()(()))))
  62.   (E2q (getNestedCount '(1 2 (3 4 (5)))))
  63.   (E3q (getNestedCount '(1 2 3 4 5 (6 (7 (8 ) ) ) ( ( ( ( 9 ) ( (0 ))))))))
  64.   (E1a 0)
  65.   (E2a 5)
  66.   (E3a 10)
  67.   (F1q (_F4 '(9 8 7 6 5 4 3 2 1 0)))
  68.   (F2q (_F3 '(9 8 7 6 5 4 3 2 1 0)))
  69.   (F3q (_F5 '(9 8 7 6 5 4 3 2 1 0)))
  70.   (F1a '(9 8 7 6))
  71.   (F2a '(9 8 7))
  72.   (F3a '(9 8 7 6 5))
  73.   )
  74.   ;Check to see if the Test and the Answer are the same!
  75.   (print 'Total::)
  76.   (print (* (/ (+
  77.    (if (_eq A1q A1a) 1 0)
  78.    (if (_eq A2q A2a) 1 0)
  79.    (if (_eq A3q A3a) 1 0)
  80.    (if (_eq B1q B1a) 1 0)
  81.    (if (_eq B2q B2a) 1 0)
  82.    (if (_eq B3q B3a) 1 0)
  83.    (if (_eq C1q C1a) 1 0)
  84.    (if (_eq C2q C2a) 1 0)
  85.    (if (_eq C3q C3a) 1 0)
  86.    (if (_eq D1q D1a) 1 0)
  87.    (if (_eq D2q D2a) 1 0)
  88.    (if (_eq D3q D3a) 1 0)
  89.    (if (_eq E1q E1a) 1 0)
  90.    (if (_eq E2q E2a) 1 0)
  91.    (if (_eq E3q E3a) 1 0)
  92.    (if (_eq F1q F1a) 1 0)
  93.    (if (_eq F2q F2a) 1 0)
  94.    (if (_eq F3q F3a) 1 0)
  95.   ) 18) 50))
  96.   (writeln '/50)
  97.   (writeln '~~~~~~~~~~~~~~~~)
  98.   (writeln '~~~~~~~~~~~~~~~~)
  99.   ;This was an afterthought, but let's redo the testing for each individual problem
  100.   ; so that students can see where they messed up, if they did.
  101.   ; You can optimize this code but it was auto generated and it works, so whatever.
  102.   (print 'A_buildLR::)
  103.   (print (+
  104.    (if (_eq A1q A1a) 1 0)
  105.    (if (_eq A2q A2a) 1 0)
  106.    (if (_eq A3q A3a) 1 0)))
  107.   (writeln '/3)
  108.   (writeln '~~~~~~~~~~~~~~~~)
  109.   (print 'B_listMins::)
  110.   (print (+
  111.    (if (_eq B1q B1a) 1 0)
  112.    (if (_eq B2q B2a) 1 0)
  113.    (if (_eq B3q B3a) 1 0)))
  114.   (writeln '/3)
  115.   (writeln '~~~~~~~~~~~~~~~~)
  116.   (print 'C_unwind::)
  117.   (print (+
  118.    (if (_eq C1q C1a) 1 0)
  119.    (if (_eq C2q C2a) 1 0)
  120.    (if (_eq C3q C3a) 1 0)))
  121.   (writeln '/3)
  122.   (writeln '~~~~~~~~~~~~~~~~)
  123.   (print 'D_functionWinner::)
  124.   (print (+
  125.    (if (_eq D1q D1a) 1 0)
  126.    (if (_eq D2q D2a) 1 0)
  127.    (if (_eq D3q D3a) 1 0)))
  128.   (writeln '/3)
  129.   (writeln '~~~~~~~~~~~~~~~~)
  130.   (print 'E_getNestedCount::)
  131.   (print (+
  132.    (if (_eq E1q E1a) 1 0)
  133.    (if (_eq E2q E2a) 1 0)
  134.    (if (_eq E3q E3a) 1 0)))
  135.   (writeln '/3)
  136.   (writeln '~~~~~~~~~~~~~~~~)
  137.   (print 'F_makeCutter::)
  138.   (print (+
  139.    (if (_eq F1q F1a) 1 0)
  140.    (if (_eq F2q F2a) 1 0)
  141.    (if (_eq F3q F3a) 1 0)))
  142.   (writeln '/3)
  143.   (writeln '~~~~~~~~~~~~~~~~)
  144. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement