-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stage1_checker.rkt
117 lines (107 loc) · 9.66 KB
/
Stage1_checker.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#lang racket
(require "Stage1_ppt.rkt")
; ignorați următoarele linii de cod...
(define show-defaults 999) ; câte exerciții la care s-au întors rezultate default să fie arătate detaliat
(define prepend #t) (define nopoints #f) (define name-ex '(testul testele trecut capitolul))
(define default-results `(#f 0 () your-code-here)) (define (default-result r) (set! default-results (cons r default-results))) (define : 'separator) (define punct 'string) (define puncte 'string) (define BONUS 'string) (define exerciții 'string)
(define total 0) (define all '()) (define n-ex 0) (define p-ex 0) (define n-exercs -1) (define default-returns '()) (define (ex n sep p . s) (set! n-ex n) (set! p-ex p) (set! all (cons (list n p) all))) (define exercițiul ex) (define (sunt n s) (set! n-exercs n)) (define s-a string-append)
(define (p . L) (map (λ (e) (display e) (when (> (string-length (format "~a" e)) 0) (display " "))) L) (newline)) (define (p-n-ex) (format "[~a]" (if nopoints (string-join (list (symbol->string (cadddr name-ex)) (number->string n-ex) "/" (number->string n-exercs))) n-ex)))
(define (epart ep% pfix full) (if (< (caddr ep%) 1) (s-a pfix (if full "" (s-a (symbol->string (car name-ex)) " ")) (if (and nopoints (not full)) "" (number->string n-ex)) (symbol->string (cadr ep%))) (if (and nopoints (not full)) "" (s-a pfix (if full "" (s-a (symbol->string (car name-ex)) " ")) (number->string n-ex)))))
(define (whengood ep%) (let [(pts (* p-ex (caddr ep%)))] (and (if prepend (printf "+~v: " pts) (printf "~a[OK] " (p-n-ex))) (if nopoints (p (epart ep% "" #f) "rezolvat") (p (epart ep% "" #f) "rezolvat: +" pts (if (= pts 1) 'punct 'puncte))) (set! total (+ total pts)))))
(define (whenbad ep% gvn expcd msg) (and (when (member gvn default-results) (set! default-returns (cons (epart ep% "" #t) default-returns))) (when (or (not (member gvn default-results)) (<= (length default-returns) show-defaults)) (bad-res ep% gvn expcd msg))))
(define (bad-res ep% gvn expcd msg) (p (if prepend "+0.0:" (format "~a[--]" (p-n-ex))) (epart ep% "la " #f) 'rezultatul gvn msg expcd))
(define (check-conds e gvn conds) (or (null? conds) (let ([r ((car conds) gvn)]) (if (eq? r #t) (check-conds e gvn (cdr conds)) (whenbad e gvn "" (or r "nu îndeplinește condiția"))))))
(define (check-part part per given main-test expected . conds) (let* ([e (list n-ex part per)] [p? (pair? (cdr main-test))] [p (if p? (car main-test) identity)] [t ((if p? cadr car) main-test)] [m ((if p? cddr cdr) main-test)]) (when (eq? #t (check-conds e given conds)) (if (t (p given) expected) (whengood e) (whenbad e (p given) expected m)))))
(define (check given main-test expected . conds) (apply check-part '- 1 given main-test expected conds))
(define the cons) (define is (cons equal? "diferă de cel așteptat")) (define in (cons member "nu se află printre variantele așteptate"))
(define same-set-as (cons (λ (x y) (apply equal? (map list->seteqv (list x y)))) "nu este aceeași mulțime cu"))
(define same-unique (cons (λ (x y) (and (apply = (map length (list x y))) ((car same-set-as) x y))) "nu sunt aceleași rezultate cu"))
(define (sumar) (when (and (not (null? default-returns)) (< show-defaults (length default-returns))) (p "... rezultatul implicit dat la" (cadr name-ex) (reverse default-returns))) (when (not nopoints) (p 'total: total 'puncte)))
(define (mark-helper) (printf "---~nEx puncte Total până aici~n") (foldr (λ (e-p t) (p (car e-p) ': (cadr e-p) "puncte. total 1 -" (car e-p) ': (+ t (cadr e-p))) (+ t (cadr e-p))) 0 all) (newline))
(sunt 5 exerciții)
(exercițiul 1 : 20 puncte)
(check-part 'a (/ 1 4) (dot-product '(-1 2 2) '(3 4 5)) is 15)
(check-part 'b (/ 1 4) (dot-product '(4) '(8)) is 32)
(check-part 'c (/ 1 4) (dot-product '( 2 0 -1 -3 -1 -1 -2 2 -3 -2)
'(-2 -2 0 2 -2 1 0 -1 0 2)) is -15)
(check-part 'd (/ 1 4) (dot-product '(-7 -30 82 40 1)
'(98 -68 -70 37 -21)) is -2927)
(exercițiul 2 : 20 puncte)
(check-part 'a (/ 1 4) (multiply '((1 2 2) (2 1 2) (2 2 3)) '(3 4 5)) is '(21 20 29))
(check-part 'b (/ 1 4) (multiply '((4 3 4) (3 4 4) (-3 -5 -3)) '(0 1 0)) is '(3 4 -5))
(check-part 'c (/ 1 4) (multiply
'(( 2 0 -2 0)
( 2 -3 1 -1)
(-3 -3 1 -1)
( 1 -2 -1 2)) '(-1 1 -1 -2)) is '(0 -4 1 -6))
(check-part 'd (/ 1 4) (multiply
'(( 3 4 4 0 4)
(-2 -3 -1 1 1)
( 3 -3 -1 2 0)
(-5 -5 -3 -4 -5)
(-4 -5 -1 1 -3)) '(-4 2 1 4 -2)) is
'(-8 3 -11 1 15))
(exercițiul 3 : 40 puncte)
(check-part 'a (/ 1 20) (get-transformations 8) is '(2 1))
(check-part 'b (/ 1 20) (get-transformations 64) is '(1 3 2 3))
(check-part 'c (/ 1 20) (get-transformations 1) is '())
(check-part 'd (/ 1 20) (get-transformations 16) is '(1 1 3))
(check-part 'e (/ 1 20) (get-transformations 18) is '(1 2 2))
(check-part 'f (/ 1 20) (get-transformations 28) is '(2 2 3))
(check-part 'g (/ 1 20) (get-transformations 4) is '(3))
(check-part 'h (/ 1 20) (get-transformations 53) is '(1 2 2 1))
(check-part 'i (/ 1 20) (get-transformations 55) is '(1 2 2 3))
(check-part 'j (/ 1 20) (get-transformations 74) is '(2 1 3 1))
(check-part 'k (/ 1 20) (get-transformations 79) is '(2 2 1 3))
(check-part 'l (/ 1 20) (get-transformations 108) is '(3 2 2 2))
(check-part 'm (/ 1 20) (get-transformations 119) is '(3 3 3 1))
(check-part 'n (/ 1 20) (get-transformations 158) is '(1 2 2 1 1))
(check-part 'o (/ 1 20) (get-transformations 244) is '(2 2 2 2 3))
(check-part 'p (/ 1 20) (get-transformations 353) is '(3 3 2 3 1))
(check-part 'q (/ 1 20) (get-transformations 482) is '(1 2 2 2 1 1))
(check-part 'r (/ 1 20) (get-transformations 764) is '(2 2 3 3 2 1))
(check-part 's (/ 1 20) (get-transformations 887) is '(3 1 2 2 1 1))
(check-part 't (/ 1 20) (get-transformations 923) is '(3 1 3 3 1 1))
(exercițiul 4 : 20 puncte)
(check-part 'a (/ 1 20) (apply-matrix-transformations '(1 3 2 3) '(3 4 5)) is '(517 1044 1165))
(check-part 'b (/ 1 20) (apply-matrix-transformations '(3) '(3 4 5)) is '(5 12 13))
(check-part 'c (/ 1 20) (apply-matrix-transformations '(3 1) '(3 4 5)) is '(45 28 53))
(check-part 'd (/ 1 20) (apply-matrix-transformations '(2 2) '(3 4 5)) is '(119 120 169))
(check-part 'e (/ 1 20) (apply-matrix-transformations '(1) '(3 4 5)) is '(15 8 17))
(check-part 'f (/ 1 20) (apply-matrix-transformations '(2) '(15 8 17)) is '(65 72 97))
(check-part 'g (/ 1 20) (apply-matrix-transformations '(3) '(5 12 13)) is '(7 24 25))
(check-part 'h (/ 1 20) (apply-matrix-transformations '(1) '(33 56 65)) is '(209 120 241))
(check-part 'i (/ 1 20) (apply-matrix-transformations '(1 1) '(5 12 13)) is '(117 44 125))
(check-part 'j (/ 1 20) (apply-matrix-transformations '(2 3) '(119 120 169)) is '(1275 2668 2957))
(check-part 'k (/ 1 20) (apply-matrix-transformations '(2 1) '(119 120 169)) is '(2665 1272 2953))
(check-part 'l (/ 1 20) (apply-matrix-transformations '(1 2) '(21 20 29)) is '(319 360 481))
(check-part 'm (/ 1 20) (apply-matrix-transformations '(1 2 3) '(55 48 73)) is '(1343 2976 3265))
(check-part 'n (/ 1 20) (apply-matrix-transformations '(3 3 2) '(45 28 53)) is '(1827 1564 2405))
(check-part 'o (/ 1 20) (apply-matrix-transformations '(2 2 2 2) '(273 136 305)) is '(242505 242368 342857))
(check-part 'p (/ 1 20) (apply-matrix-transformations '(2 1 2 1) '(133 156 205)) is '(56661 28420 63389))
(check-part 'q (/ 1 20) (apply-matrix-transformations '(1 3 1 1 2) '(3 4 5)) is '(1971 2300 3029))
(check-part 'r (/ 1 20) (apply-matrix-transformations '(1 1 2 2 1) '(33 56 65)) is '(47229 22300 52229))
(check-part 's (/ 1 20) (apply-matrix-transformations '(3 2 1 3 2 3 2 3) '(21 20 29)) is '(823347 1645604 1840085))
(check-part 't (/ 1 20) (apply-matrix-transformations '(2 3 2 3 2 2 3 1 3) '(697 696 985)) is '(218568525 383614372 441511253))
(exercițiul 5 : 20 puncte)
(check-part 'a (/ 1 20) (get-nth-ppt-from-matrix-transformations 64) is '(517 1044 1165))
(check-part 'b (/ 1 20) (get-nth-ppt-from-matrix-transformations 1) is '(3 4 5))
(check-part 'c (/ 1 20) (get-nth-ppt-from-matrix-transformations 4) is '(5 12 13))
(check-part 'd (/ 1 20) (get-nth-ppt-from-matrix-transformations 5) is '(35 12 37))
(check-part 'e (/ 1 20) (get-nth-ppt-from-matrix-transformations 10) is '(39 80 89))
(check-part 'f (/ 1 20) (get-nth-ppt-from-matrix-transformations 15) is '(133 156 205))
(check-part 'g (/ 1 20) (get-nth-ppt-from-matrix-transformations 17) is '(273 136 305))
(check-part 'h (/ 1 20) (get-nth-ppt-from-matrix-transformations 19) is '(115 252 277))
(check-part 'i (/ 1 20) (get-nth-ppt-from-matrix-transformations 24) is '(319 360 481))
(check-part 'j (/ 1 20) (get-nth-ppt-from-matrix-transformations 55) is '(741 1540 1709))
(check-part 'k (/ 1 20) (get-nth-ppt-from-matrix-transformations 99) is '(1265 1248 1777))
(check-part 'l (/ 1 20) (get-nth-ppt-from-matrix-transformations 142) is '(1071 1840 2129))
(check-part 'm (/ 1 20) (get-nth-ppt-from-matrix-transformations 149) is '(1073 264 1105))
(check-part 'n (/ 1 20) (get-nth-ppt-from-matrix-transformations 210) is '(3145 2928 4297))
(check-part 'o (/ 1 20) (get-nth-ppt-from-matrix-transformations 359) is '(551 240 601))
(check-part 'p (/ 1 20) (get-nth-ppt-from-matrix-transformations 465) is '(16929 18560 25121))
(check-part 'q (/ 1 20) (get-nth-ppt-from-matrix-transformations 525) is '(3913 3216 5065))
(check-part 'r (/ 1 20) (get-nth-ppt-from-matrix-transformations 609) is '(1495 1848 2377))
(check-part 's (/ 1 20) (get-nth-ppt-from-matrix-transformations 786) is '(24465 21632 32657))
(check-part 't (/ 1 20) (get-nth-ppt-from-matrix-transformations 960) is '(9499 11220 14701))
(sumar)