-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecondAssignment.lsp
114 lines (90 loc) · 2.76 KB
/
SecondAssignment.lsp
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
;Assignment 2
;Question 1
; a. yes
; b. no
; c. no
; d. yes
; e. no
; f. yes
; g. yes
;Question 2
; a. single atom
; b. single list with 4 elements
; c. neither
; d. neither.
; e. single list with 2 elements
; f. neither
; g. single list with 3 elements
; h. single list with 2 elements
;Question 3 the ' symbol in here means literally those values, so literally A B C
(setf x '(A B C))
(append x x)
;Question 4
(QUOTE (QUOTE (A)))
; 'a = (QUOTE A) is a list of two symbols that evaluates to the symbol A.
;Question 5
; a.
(setq y (list 'a 'b))
; b. car is used to get the first value in a list which is a in this case
; to get the second value in a list, you would use cadr eg: cadr y
(list 'd (car y))
;Question 6
(defun sqr
(x)
(list (+ x x x x) (* x x)))
;Question 7
(defun quadratic (a b c)
(list (/ (+ (- b)
(sqrt (- (* b b) (* 4 a c))))
(* 2 a))
(/ (- (- b)
(sqrt (- (* b b) (* 4 a c))))
(* 2 a))))
;Question 8
(defun areaOfCircle
(r)
(* pi (* r r)))
;Question 9
;Fahrenheit to celsius: (Temp-32)* (5/9)
(defun FTOC
(temp)
(* (- temp 32) (/ 5 9)))
;Question 10 rest gets everything from the list besides the first element
(defun rotate-left
(whole-list)
(append (rest whole-list) (list (first whole-list))))
;Question 11
(defun distancePoints
(firstList secondList)
(sqrt (+ (* (- (car firstList) (car secondList)) (- (car firstList) (car secondList)))
(* (- (cadr firstList) (cadr secondList)) (- (cadr firstList) (cadr secondList))))))
;Question 12
(defun HEAD
(myList)
(first myList))
(defun TAIL
(myList)
(rest myList))
;Question 13
(defun SWITCH
(myList)
(append (rest myList) (list (first myList))))
;Question 14
;70.
; ANSWER VERIFIED AND CHECKED
;Question 15
; a) (caddr e)
; b) (car (car (cdr (car (cdr e)))))
; c) (car (car (cdr (car (cdr (car (car '(((A (B (X) D)))))))))))
;Question 16
; a) (cons 'a (cons 'b (cons 'x (cons 'd nil))))
; b) (cons 'a (cons (cons 'b (cons (cons 'x (cons 'd nil)) nil)) nil))
; c) (cons (cons (cons 'a (cons (cons 'b (cons (cons 'x nil) (cons 'd nil))) nil)) nil) nil)
;Question 17
(list (cons (list (caar e) (cadar e)) (cddar e)) (append (list 'a 'b) (cdr (cdr (caddr e)))))
;Question 18
(list (append (list (caar e) 'a) (cddar e)) (cadadr e) (cadr (cdaddr e)) (append (list (car (cddadr e))) (cdr (cdr (caddr e))$
;Question 19
((90 91 92 93 94 95 96 97 98 99 3) (+ 3 4 – 29 39 49 59 69 79 89 99))
;Question 20
(append (list (caar e))(append (list (append (list (car(cdaddr e)))(list (cadr (cdaddr e))))) (cddr (cdaddr e))))