-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThirdAssignment.lsp
More file actions
90 lines (82 loc) · 1.96 KB
/
ThirdAssignment.lsp
File metadata and controls
90 lines (82 loc) · 1.96 KB
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
; Solution to Problem 1
(defun MIN-2
(x y)
(if (and (numberp x) (numberp y))
(if (<= x y)
x
y)
'error))
; Solution to Problem 2
(defun SAFE-AVG
(x y)
(if (and (numberp x) (numberp y))
(/ (+ x y) 2)))
; Solution to Problem 3
(defun ODD-GT-MILLION
(x)
(if (integerp x)
(and (oddp x) (< 1000000 x))))
; Solution to Problem 4
(defun MULTIPLE-MEMBER
(x y)
(if (and (or (numberp x) (symbolp x)) (listp y))
(member x (cdr (member x y)))
(list 'ERROR)))
; Solution to Problem 5
(defun MONTH->INTEGER
(x)
(if (eq x 'January)
1
(if(eq x 'February)
2
(if(eq x 'March)
3
(if(eq x 'April)
4
(if(eq x 'May)
5
(if(eq x 'June)
6
(if(eq x 'July)
7
(if(eq x 'August)
8
(if(eq x 'September)
9
(if(eq x 'October)
10
(if(eq x 'November)
11
(if(eq x 'December)
12
'Error)))))))))))))
; Solution to Problem 6
(defun SCORE->GRADE
(x)
(if (numberp x)
(cond
((and (>= x 90)) 'A)
((and (< x 90) (>= x 87)) 'A-)
((and (< x 87) (>= x 83)) 'B+)
((and (< x 83) (>= x 80)) 'B)
((and (< x 80) (>= x 77)) 'B-)
((and (< x 77) (>= x 73)) 'C+)
((and (< x 73) (>= x 70)) 'C)
((and (< x 70) (>= x 60)) 'D)
((and (< x 60)) 'F)
(t nil)
)
nil))
; Solution to Problem 7
(defun GT
(x y)
(and (and (numberp x) (numberp y)) (> x y)))
; Solution to Problem 8
(defun SAME-SIGN
(x y)
(and (and (numberp x) (numberp y))
(or (and (zerop x) (zerop y)) (and (minusp x) (minusp y)) (and (plusp x) (plusp y)))))
; Solution to Problem 9
(defun SAFE-DIV
(x y)
(and (and (and (numberp x) (numberp y)) (not (zerop y))) (/ x y)))