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,24 @@
|
||||
;;; LOOPS 5: DO AND DO* (solution)
|
||||
|
||||
(defun triangle-do (n)
|
||||
(do ((i 1 (1+ i))
|
||||
(total 0 (+ total i)))
|
||||
((> i n) total)))
|
||||
|
||||
(defun factorial-of (n)
|
||||
(do* ((a 1 (1+ a))
|
||||
(b 1 (* b a)))
|
||||
((>= a n) b)))
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||
;;; them unchanged.
|
||||
;;; ------------------------------------------------------------------
|
||||
|
||||
(check-equal 6 (triangle-do 3))
|
||||
(check-equal 55 (triangle-do 10))
|
||||
(check-equal 0 (triangle-do 0))
|
||||
(check-equal 1 (factorial-of 0))
|
||||
(check-equal 1 (factorial-of 1))
|
||||
(check-equal 6 (factorial-of 3))
|
||||
(check-equal 24 (factorial-of 4))
|
||||
Reference in new issue
Block a user