Challenge Problems about
In this section you'll be asked to write and evaluate some
We want all iteration in your answers to be done with
Our answers to the problems in this section are in community-books
file
LP14-1: Make a list of the integers from 10 down to 0.
Expected Value:
Ok, we know this is a silly question if taken literally! Why use iteration at all if the answer is a constant? If you want to cheat, just enter
(loop$ with ans = '(10 9 8 7 6 5 4 3 2 1 0) do (return ans))
But the spirit of these questions is to use iteration and, if it helps,
imagine we'd asked you to write a
LP14-2: Sum the naturals less than or equal to 100.
Expected Value:
Hint: Write the
LP14-3: Sum the squares of the naturals less than or equal to 100, using the following function to square.
(defun sq (x) (* x x))
Expected Value:
LP14-4: Write a
Expected Value:
LP14-5: Fill in the blank below so that the next form is a theorem. You do not have to prove the theorem (but it shouldn't be hard).
(defun do-loop$-member (e lst) (loop$ ...)) (defthm lp14-5 (equal (do-loop$-member e lst) (member e lst)) :rule-classes nil)——————————
LP14-6: Given the following
(defun steps-for-member (e lst steps) (cond ((endp lst) (list steps nil)) ((equal (car lst) e) (list steps lst)) (t (steps-for-member e (cdr lst) (+ 1 steps)))))
fill in the blank so that this is a theorem.
(defthm lp14-6 (equal (loop$ ...) (steps-for-member e lst steps)) :rule-classes nil)——————————
LP14-7:Write a
Expected Value:
((1 . 1) (1 . 2) (1 . 3) (1 . 4) (2 . 1) (2 . 2) (2 . 3) (2 . 4) (3 . 1) (3 . 2) (3 . 3) (3 . 4))——————————
Now go to lp-section-15 (or return to the