POSTSCRIPT EXERCISES READING ------- Notes for lecture 7. Sedgewick, p. 141 SUPPLEMENTAL READING -------------------- See course FAQ page EXERCISES --------- For Questions 1-5, assume that the stack is initially empty, and give the contents of the stack after the given PostScript program is executed. 1. 1 dup add dup add dup add dup add 2. 1 dup mul dup mul dup mul dup mul 3. 2 dup mul dup mul dup mul dup mul 4. 1 1 2 copy add 2 copy add 2 copy add 2 copy add [Note: "copy" pops an integer N off the stack, then copies the N integers at the top of the stack. "1 copy" is the same as "dup".] 5. 1 1 10 { 2 copy add } repeat [Note: "N {...} repeat" executes the grouped sequence N times.] 6. What does the following Postscript program do? %! 200 200 moveto 100 100 rlineto 200 300 moveto 100 -100 rlineto stroke showpage 7. What does the following Postscript program do? %! 100 -100 200 300 100 100 200 200 moveto rlineto moveto rlineto stroke showpage 8. What does the following Postscript program do? %! 200 200 moveto 300 300 lineto 200 300 moveto 300 200 lineto stroke showpage 9. Write a Postscript program to draw a "T". . . . . ANSWERS TO POSTSCIPT EXERCISES 1. 16 2. 1 3. 65536 (A few more "dup mul" operations would caluculate some truly huge integers: PostScript eventually represents them as "infinity" rather than overflowing.) 4. 1 1 2 3 5 8 (Fibonacci numbers.) 5. 1 1 2 3 5 8 13 21 34 55 89 144 6. Draws an "X". 7. Same thing. 8. Same thing. 9. %! 200 200 moveto 0 100 rlineto 150 300 moveto 100 0 rlineto stroke showpage