-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stage2_checker.rkt
135 lines (124 loc) · 11 KB
/
Stage2_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#lang racket
(require "Stage2_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 6 exerciții)
(define (FQ1 V) (apply Q1 V))
(define (FQ2 V) (apply Q2 V))
(define (FQ3 V) (apply Q3 V))
(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 : 20 puncte)
(check-part 'a (/ 1 10) (apply-functional-transformations (list reverse ((curry map) add1) cdr) '(3 4 5)) is '(5 4))
(check-part 'b (/ 1 10) (apply-functional-transformations (list ((curry filter) even?)) '(3 5 3 12 5 39)) is '(12))
(check-part 'c (/ 1 10) (apply-functional-transformations (list ((curry map) sqr) ((curry apply) +)) '(-1 2 3)) is 14)
(check-part 'd (/ 1 10) (apply-functional-transformations (list ((curry map) (lambda (x) (- x))) reverse ((curry apply) -)) '(1 -2 3 -4)) is 6)
(check-part 'e (/ 1 10) (apply-functional-transformations (list FQ2 FQ1) '(1 2 3 5)) is '(11 3 14 17))
(check-part 'f (/ 1 10) (apply-functional-transformations (list FQ1 FQ3 FQ1 FQ2) '(3 2 5 7)) is '(43 34 77 111))
(check-part 'g (/ 1 10) (apply-functional-transformations (list FQ2 FQ3) '(15 13 28 41)) is '(41 69 110 179))
(check-part 'h (/ 1 10) (apply-functional-transformations (list FQ3 FQ1 FQ1) '(1 2 3 5)) is '(13 3 16 19))
(check-part 'i (/ 1 10) (apply-functional-transformations (list FQ2 FQ1 FQ1 FQ3 FQ1 FQ3) '(23 14 37 51)) is '(671 907 1578 2485))
(check-part 'j (/ 1 10) (apply-functional-transformations (list FQ3 FQ3 FQ1 FQ2 FQ1 FQ2 FQ2 FQ1) '(13 8 21 29)) is '(3803 1103 4906 6009))
(exercițiul 4 : 20 puncte)
(when (not (equal? get-nth-ppt-from-matrix-transformations 'your-code-here))
(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 3) is '(21 20 29))
(check-part 'd (/ 1 20) (get-nth-ppt-from-matrix-transformations 9) is '(119 120 169))
(check-part 'e (/ 1 20) (get-nth-ppt-from-matrix-transformations 15) is '(133 156 205))
(check-part 'f (/ 1 20) (get-nth-ppt-from-matrix-transformations 17) is '(273 136 305))
(check-part 'g (/ 1 20) (get-nth-ppt-from-matrix-transformations 27) is '(697 696 985))
(check-part 'h (/ 1 20) (get-nth-ppt-from-matrix-transformations 55) is '(741 1540 1709))
(check-part 'i (/ 1 20) (get-nth-ppt-from-matrix-transformations 99) is '(1265 1248 1777))
(check-part 'j (/ 1 20) (get-nth-ppt-from-matrix-transformations 142) is '(1071 1840 2129))
(check-part 'k (/ 1 20) (get-nth-ppt-from-matrix-transformations 195) is '(2449 2640 3601))
(check-part 'l (/ 1 20) (get-nth-ppt-from-matrix-transformations 210) is '(3145 2928 4297))
(check-part 'm (/ 1 20) (get-nth-ppt-from-matrix-transformations 218) is '(4641 2840 5441))
(check-part 'n (/ 1 20) (get-nth-ppt-from-matrix-transformations 366) is '(481 600 769))
(check-part 'o (/ 1 20) (get-nth-ppt-from-matrix-transformations 465) is '(16929 18560 25121))
(check-part 'p (/ 1 20) (get-nth-ppt-from-matrix-transformations 525) is '(3913 3216 5065))
(check-part 'q (/ 1 20) (get-nth-ppt-from-matrix-transformations 609) is '(1495 1848 2377))
(check-part 'r (/ 1 20) (get-nth-ppt-from-matrix-transformations 701) is '(45123 21364 49925))
(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))
)
(exercițiul 5 : 20 puncte)
(when (not (equal? get-nth-quadruple 'your-code-here))
(check-part 'a (/ 1 20) (get-nth-quadruple 1) is '(1 1 2 3))
(check-part 'b (/ 1 20) (get-nth-quadruple 2) is '(3 1 4 5))
(check-part 'c (/ 1 20) (get-nth-quadruple 3) is '(3 2 5 7))
(check-part 'd (/ 1 20) (get-nth-quadruple 6) is '(5 4 9 13))
(check-part 'e (/ 1 20) (get-nth-quadruple 7) is '(3 4 7 11))
(check-part 'f (/ 1 20) (get-nth-quadruple 10) is '(3 5 8 13))
(check-part 'g (/ 1 20) (get-nth-quadruple 12) is '(5 3 8 11))
(check-part 'h (/ 1 20) (get-nth-quadruple 31) is '(3 8 11 19))
(check-part 'i (/ 1 20) (get-nth-quadruple 99) is '(23 16 39 55))
(check-part 'j (/ 1 20) (get-nth-quadruple 103) is '(5 12 17 29))
(check-part 'k (/ 1 20) (get-nth-quadruple 175) is '(5 19 24 43))
(check-part 'l (/ 1 20) (get-nth-quadruple 333) is '(47 34 81 115))
(check-part 'm (/ 1 20) (get-nth-quadruple 399) is '(69 44 113 157))
(check-part 'n (/ 1 20) (get-nth-quadruple 489) is '(137 84 221 305))
(check-part 'o (/ 1 20) (get-nth-quadruple 511) is '(51 65 116 181))
(check-part 'p (/ 1 20) (get-nth-quadruple 667) is '(43 77 120 197))
(check-part 'q (/ 1 20) (get-nth-quadruple 719) is '(171 53 224 277))
(check-part 'r (/ 1 20) (get-nth-quadruple 914) is '(67 12 79 91))
(check-part 's (/ 1 20) (get-nth-quadruple 1792) is '(71 115 186 301))
(check-part 't (/ 1 20) (get-nth-quadruple 2502) is '(167 115 282 397))
)
(exercițiul 6 : 20 puncte)
(when (not (equal? get-nth-ppt-from-GH-quadruples 'your-code-here))
(check-part 'a (/ 1 20) (get-nth-ppt-from-GH-quadruples 64) is '(517 1044 1165))
(check-part 'b (/ 1 20) (get-nth-ppt-from-GH-quadruples 2) is '(15 8 17))
(check-part 'c (/ 1 20) (get-nth-ppt-from-GH-quadruples 210) is '(3145 2928 4297))
(check-part 'd (/ 1 20) (get-nth-ppt-from-GH-quadruples 218) is '(4641 2840 5441))
(check-part 'e (/ 1 20) (get-nth-ppt-from-GH-quadruples 359) is '(551 240 601))
(check-part 'f (/ 1 20) (get-nth-ppt-from-GH-quadruples 366) is '(481 600 769))
(check-part 'g (/ 1 20) (get-nth-ppt-from-GH-quadruples 465) is '(16929 18560 25121))
(check-part 'h (/ 1 20) (get-nth-ppt-from-GH-quadruples 525) is '(3913 3216 5065))
(check-part 'i (/ 1 20) (get-nth-ppt-from-GH-quadruples 609) is '(1495 1848 2377))
(check-part 'j (/ 1 20) (get-nth-ppt-from-GH-quadruples 786) is '(24465 21632 32657))
(check-part 'k (/ 1 20) (get-nth-ppt-from-GH-quadruples 811) is '(22223 46464 51505))
(check-part 'l (/ 1 20) (get-nth-ppt-from-GH-quadruples 960) is '(9499 11220 14701))
(check-part 'm (/ 1 20) (get-nth-ppt-from-GH-quadruples 1212) is '(78715 88548 118477))
(check-part 'n (/ 1 20) (get-nth-ppt-from-GH-quadruples 2581) is '(11001 17000 20249))
(check-part 'o (/ 1 20) (get-nth-ppt-from-GH-quadruples 3250) is '(5809 11640 13009))
(check-part 'p (/ 1 20) (get-nth-ppt-from-GH-quadruples 4169) is '(61721 41760 74521))
(check-part 'q (/ 1 20) (get-nth-ppt-from-GH-quadruples 5159) is '(255825 155992 299633))
(check-part 'r (/ 1 20) (get-nth-ppt-from-GH-quadruples 6321) is '(1242261 1103780 1661789))
(check-part 's (/ 1 20) (get-nth-ppt-from-GH-quadruples 7298) is '(753457 341376 827185))
(check-part 't (/ 1 20) (get-nth-ppt-from-GH-quadruples 8112) is '(140505 119288 184313))
)
(sumar)