Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table
This commit is contained in:
1 parent
77843402fa
commit
4675bd1106
76 files changed
+2505
-14
No files matched your search
@@ -0,0 +1,25 @@
|
||||
;;; SEQUENCES 3: SORT, :KEY, REVERSE (solution)
|
||||
|
||||
(defun ascending (xs)
|
||||
(sort xs #'<))
|
||||
|
||||
(defun by-price (alist)
|
||||
(sort alist #'< :key #'cdr))
|
||||
|
||||
(defun back-words (xs)
|
||||
(mapcar #'reverse xs))
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||
;;; them unchanged.
|
||||
;;; ------------------------------------------------------------------
|
||||
|
||||
(check-equal '(1 2 3) (ascending (list 3 1 2)))
|
||||
(check-equal '(-1 0 4) (ascending (list 4 0 -1)))
|
||||
(check-equal '(3 2 1) (reverse (list 1 2 3)))
|
||||
(check-equal '((tea . 1) (cola . 2))
|
||||
(by-price (list (cons 'cola 2) (cons 'tea 1))))
|
||||
(check-equal '((b . 1) (c . 2) (a . 7))
|
||||
(by-price (list (cons 'a 7) (cons 'b 1) (cons 'c 2))))
|
||||
(check-equal '("tac" "esaelp") (back-words '("cat" "please")))
|
||||
(check-equal '("bba" "aa") (back-words '("abb" "aa")))
|
||||
Reference in new issue
Block a user